今天遇到一個奇葩的問題我使用bus.js傳值然后兄弟組件里面出現(xiàn)一個很怪的問題,我使用2號模塊先制作值,然后3號模塊獲取,但是獲取不到。我使用3號模塊在前就可以。一般邏輯不是得先由2號模塊先做好值然后3號回去嘛,怎么現(xiàn)在我3號在前反而能實現(xiàn)呢??<template>
<div>
<demo-val2></demo-val2>
<demo-val3></demo-val3>
</div></template><script>
import demoVal2 from './demo2.vue'
import demoVal3 from './demo3.vue'
export default { name: '', components: {
demoVal2,
demoVal3
}
}</script><template>
<div>demo2</div></template><script>
import bus from './bus.js'
export default { name: "demo2",
mounted() { console.log(2222)
bus.$emit('val', 'toval')
}
}</script><template>
<div>demo3</div></template><script>
import bus from './bus.js'
export default { name: "demo3",
mounted() { console.log(3333)
bus.$on('val', (data) => { console.log(data)
})
}
}</script>不顯示123
/*******************************************/
交換一下<template>
<div>
<demo-val3></demo-val3>
<demo-val2></demo-val2>
</div></template>輸出123這是為什么呢????
vue 奇葩問題
慕森王
2019-03-25 11:39:04