实例:
父组件:
app.component('父组件', {
data() {
return {
todos: ['Feed a cat', 'Buy tickets']
}
},
provide() {
return {
todoLength: this.todos.length
}
},
template: `
...
`
})后代组件:
app.component('某一个隔了很多代的同系组件', {
inject: ['todoLength'],
created() {
console.log(`Injected property: ${this.todoLength}`) // > 注入的 property: 2
}
})