向vue.js组件添加自定义属性

克里斯86

如何在vue组件中设置自定义属性?

var myComponent = Vue.extend({
    data: function() {
        return {
            item: {}
        }
    },

    created: function() {
        // This does not seem to work
        this.item.customProperty = 'customProperty';
    }
});

您可以使用Vue.set添加反应性:

var myComponent = Vue.extend({
    data: function() {
        return {
            item: {}
        }
    },

    created: function() {
        Vue.set(this.item, 'customProperty', 'customProperty');
    }
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章