The structure of vue devtool is as follows
Root
Header
App
comment
How to get app.vue (without vuex) comment.vue (name is set to comment) data
// app.vue
export default {
name: 'app',
data: () => ({
from: 'form app'
}),
watch: {
'$route': 'routeChange'
},
created () {
},
methods: {
routeChange (to, from) {
//这里如何获取comment.vue的data呢?
}
}
}
// comment.vue
export default {
name: 'comment',
data: () => ({
test: '1'
})
}
There are 2 communication methods between components in vue
The parent component uses props to pass data to the child component, and the child component uses emit to send events to notify the parent component
Use vuex
In fact, there is another way to define shared variables between components, such as global variables. This is similar to vuex, but vuex provides more control
Create a new empty vue instance for bus connection
It is written in the document