84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
app.vue page
bPage
I want page b to trigger the custom event of app.vue,
But it says bus is not defined. I want to know how to introduce it?
业精于勤,荒于嬉;行成于思,毁于随。
bus is brought up and placed in a specific place.
1. Create bus.js
// bus.js import Vue from 'vue'; export default new Vue();
2. Statement
import Bus from 'bus'; export default { created() { Bus.$on('getData', target => { console.log(target); }); } }
3. Call
import Bus from 'bus'; export default{ methods: { but(event) { Bus.$emit('getData', event.target); } } }
Although this approach is not highly recommended, you can:
window.bus = new Vue();
You can’t access bus because bus is a local variable. . .
Added:
If you do not use the global event bus, you can use the plug-in method: vue-bus
In addition, if you want to share this data between multiple components, use Vuex
Just put it in the dataIt’s not clear yet, look here
bus is brought up and placed in a specific place.
1. Create bus.js
2. Statement
3. Call
Although this approach is not highly recommended, you can:
You can’t access bus because bus is a local variable. . .
Added:
If you do not use the global event bus, you can use the plug-in method: vue-bus
In addition, if you want to share this data between multiple components, use Vuex
Just put it in the data
It’s not clear yet, look here