我有一个组件需要mixin取决于它收到的道具.
const timerMixin = {
created() {
console.log("Timer mixin injected")
}
}
export default {
name: 'Component A',
props: ['hasTimer'],
mixins: this.hasTimer ? [timerMixin] : [] // fails because `this` is not available here
}
Run Code Online (Sandbox Code Playgroud)
有没有办法动态地将mixin注入组件?