目录
- 传送参数页面
- 接受参数页面
- 最后
uniapp全局事件,也就是说,不相邻的,不是父子组件,也可以传递参数。
一个组件,传递项目内所有文件其中一个里面内,可以接受到参数。
传送参数页面
<template><view class="box"><button type="default" @click="goChuangcan(521)"></button></view>
</template><script>export default{methods:{// 传送参数goChuangcan(e){uni.$emit('citySelectData',e)}}}
</script><style>.box{background-color: pink;}
</style>
接受参数页面
<template><view class="box">接受到数据啦,展示在页面上啦:------- <text style="color: #FFF;">{{dataLit}}</text></view>
</template><script>export default{data(){return{dataLit:''}}mounted() {// 注意这里是细节,一定要加 var that = this 这个var that = thisuni.$on('citySelectData',function(data){that.dataLit = dataconsole.log('接受到数据啦:',data)})}}
</script><style>.box{background-color: pink;}
</style>
最后
感觉文章好的话记得点个心心和关注和收藏,有错的地方麻烦指正一下,如果需要转载,请标明出处,多谢!!!