2020-08-18 19:05发布
复杂一点的用vuex,简单的可以使用params进行传值,
this.$router.push({ name: 'news', params: { userId: 123 }})
获取时使用this.$route.params.userId获取,
另外可通过eventBus传递数据
使用前可以在全局定义一个eventBus,window.eventBus = new Vue();
在需要传递参数的组件中,定义一个emit发送需要传递的值,键名可以自己定义(可以为对象)
eventBus.$emit('eventBusName', id);在需要接受参数的组件,用on接受该值(或对象)
最多设置5个标签!
复杂一点的用vuex,简单的可以使用params进行传值,
this.$router.push({ name: 'news', params: { userId: 123 }})
获取时使用this.$route.params.userId获取,
另外可通过eventBus传递数据
使用前可以在全局定义一个eventBus,window.eventBus = new Vue();
在需要传递参数的组件中,定义一个emit发送需要传递的值,键名可以自己定义(可以为对象)
eventBus.$emit('eventBusName', id);在需要接受参数的组件,用on接受该值(或对象)
一周热门 更多>