小编Sri*_*mam的帖子

如何将mixin动态注入组件

我有一个组件需要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注入组件?

vue.js vue-component

15
推荐指数
1
解决办法
5087
查看次数

标签 统计

vue-component ×1

vue.js ×1