| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <template>
- <view class="pages">
- <div class="form-input">
- <u-input v-model="form.name" placeholder="请输入名称" border="bottom"></u-input>
- <u-input v-model="form.phone" placeholder="请输入手机号" border="bottom"></u-input>
- </div>
- <div class="form-btn">
- <u-button type="primary" @click="save">添加</u-button>
- </div>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- form: {
- name: '',
- phone: ''
- }
- }
- },
- methods: {
- save() {
- if (this.form.name == '') {
- this.$u.toast('请输入名称')
- return
- }
- if (this.form.phone == '') {
- this.$u.toast('请输入手机号')
- return
- }
- //返回上一页并添加联系人
- let pages = getCurrentPages(); //获取所有页面栈实例列表
- let nowPage = pages[pages.length - 1]; //当前页页面实例
- let prevPage = pages[pages.length - 2]; //上一页页面实例
- console.log(prevPage.$vm.contactsList);
- prevPage.$vm.contactsList.push(this.form);
- uni.navigateBack(1)
- // this.$u.post('/api/contacts/add',this.form).then(res => {
- // if(res.code == 0){
- // this.$u.toast('添加成功')
- // setTimeout(() => {
- // uni.navigateBack({
- // delta: 1
- // })
- // }, 1000);
- // }
- // })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .pages {
- width: 100%;
- height: 100vh;
- background: #f5f5f5;
- }
- .form-input {
- background: #fff;
- padding: 10px;
- }
- .form-btn{}
- </style>
|