欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 金融 > 【Tip】父子组件传值和页面跳转传值方法(vue和uniapp)

【Tip】父子组件传值和页面跳转传值方法(vue和uniapp)

2024/10/24 21:24:11 来源:https://blog.csdn.net/xingyuemengjin/article/details/141904187  浏览:    关键词:【Tip】父子组件传值和页面跳转传值方法(vue和uniapp)

          本文介绍了在Vue和uniapp中子组件和父组件之间的传值方法、页面跳转传值方法。

一、父子组件传值

以列表为例:

1、子组件

sonTemplate.vue

(1)挂载显示内容

<el-table>

//列表内容

<el-table>

(2)关键方法

Creat()方法: 子组件列表getList()

Props:绑定要传递的值(父组件传给子组件==用于显示或在子组件上一次操作值基础上操作)

Props:{

sonValue: {
  type: Number|String,
},

}

Submit():$emit(“方法名method1”, values) 传递在子组件操作的值 (子组件传给父组件==值传递)

2、父组件

(1) 挂载内容

<son-template :sonValue=”selectValue” @method1=”getSelectValue”>

(2)关键方法

Import sonTemplate.vueCompoent:{SonTemplate}Data(){selectValue: null,}Methods:{getSelectValue(val){this.selectValue = val// 可对val做其他处理filter、map等}}

二、路由自定义页面跳转和传值(在Vue中)

1、页面跳转

this.$store.dispatch('tagsView/delView', this.$route)this.$router.push({path: '/factory/factoryCheckPlanManager/add',   //'/factory/factoryCheckPlanManager/add为跳转文件的vue目录query: {checkPlanId: id, queryParams: this.queryParams}
})

2、接收

create(){let queryParams = this.$route.query.queryParams}

三、路由自定义页面跳转和传值(在uniapp中)

1、页面跳转之===父子组件传值(子组件传递给父组件)

页面之间子页面(下一页面)可用$emit返回给父级页面(上一页面),父级页面在onShow方法中监听事件,实现页面之间的组件传值。

常用于较大数据的传送,不宜放在请求地址里

(1) 子页面传值

uni.$emit('updateCheckItem', {type:'updateCheckItem',checkItem: this.checkItem,locationId:Number(this.checkItem.checkUnitLocation)
});//返回上级页面uni.navigateBack({delta: 1
})

(2) 父页面(上一页面)接收

onShow(){uni.$off('updateCheckItem');
uni.$once('updateCheckItem', data => {if(data.type === "updateCheckItem") {that.checkList.forEach((check,key)=>{if(check.pointUnitId===data.locationId){check.checkItemList.forEach((item,index)=>{if(item.id===data.checkItem.id){that.checkList[key].checkItemList[index]=data.checkItem;}})}})uni.hideLoading();} else {console.log('失败')}
})}

2、页面跳转之===地址跳转

父页面跳转到子页面,要传递的参数值附带在请求地址上,子页面在onLoad函数中接收

(1) 父页面跳转传值

let url="sonVue?describe="+this.checkItem.abnormalDescribe+'&locationId='+this.checkItem.checkUnitLocation;
this.$tab.navigateTo(url);

(2) 子页面接收

sonVue.vue

onLoad(option){if(option.describe!=null && option.describe!='null'){this.describe=option.describe;}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com