一、新建bus.js
import Vue from 'vue'
export default new Vue();
二、A页面传值
<script>
import bus from '../../../static/js/bus';
export default {
data(){
return{
}},methods:{
click(row,index){
setTimeout(()=>{
bus.$emit('channel_id',this.row.id);},100);}}
}
</script>
三、B页面取值
created(){
bus.$on('channel_id',data=>{
this.get_channel_id = data;console.log("传过来的值"+data);console.log("赋值取出"+this.get_channel_id);});console.log("asasas:"+this.get_channel_id);
},
四、重点
赋值时把bus.$emit()放在setTimeout内