【发布时间】:2017-11-15 16:50:28
【问题描述】:
我正在尝试从 VueJS 中的 mixin 访问 provided / injected 值。我可以从任何组件中看到这些值,但不能从 mixin 中看到。我正在尝试的可能吗?
https://jsfiddle.net/frang/c6c7kqhp/2/1
let myMixin = {
inject: ['myDependency'],
created: function() {
console.log('in mixin', this.myDependency)
}
}
Vue.component('my-component', {
inject: ['myDependency'],
created: function() {
console.log('in component', this.myDependency)
}
})
new Vue({
el: '#example',
provide() {
return {
myDependency: 'here is my value'
}
},
mixins: [myMixin]
})
【问题讨论】:
标签: dependency-injection vue.js vuejs2 mixins