var Event = new Vue(); 相當於又new了一個vue實例,Event中含有vue的全部方法;
Event.$emit('msg',this.msg); 發送數據,第一個參數是發送數據的名稱,接收時還用這個名字接收,第二個參數是這個數據現在的位置;
Event.$on('msg',function(msg){ 接收數據,第一個參數是數據的名字,與發送時的名字對應,第二個參數是一個方法,要對數據的操作
/這裏是對數據的操作
})
或者新建一個空的js文件
import Vue from 'vue'
export default new Vue()
import vmson from '@/services/emptyVue'
export default {
name: 'RegionA',
props: [],
data () {
return {
PoiNames: ['旅遊景點', '餐飲', '學校', '休閒娛樂', '醫療', '超市', '便利店', '寫字樓', '小區', '酒店', '銀行', '運動健身'],
PoiList: []
}
},
methods: {
},
mounted () {
vmson.$on('poiList', (val) => { // 監聽事件poiList回調函數要使用箭頭函數 接收文件
console.log('ccc', val) //
})
}
}
</script>
另一個子組件使用
vmson.$emit('poiList', results) 去傳值