Vue.js 函数参数为this.variable

Vue.js 函数参数为this.variable,vue.js,Vue.js,我正在使用Vue.js,并希望使用一种方法处理多个问题: data: { genders: [], months: [], } methods: { getModels:function(cat,model) { $.getJSON('/api/models/' + cat + '/' + model, function(data) { this.model = data; }.bind(this)); }

我正在使用Vue.js,并希望使用一种方法处理多个问题:

data: {
    genders: [],
    months: [],
}

methods: {
    getModels:function(cat,model) {
        $.getJSON('/api/models/' + cat + '/' + model, function(data) {
            this.model = data;
        }.bind(this));
    },
},

created: {
    this.getModels('core', 'genders');
    this.getModels('core', 'months');
},

在该方法中,我希望能够使用已获取的数据选择正确的数组。但是,当我需要“模型”数据来查找“性别”和“月份”数据时,代码反而在查找“模型”数据。

如果您想通过名称访问某些数据,应该这样做

model = 'genders' // just to ilustrate the example
this[model] = data
因为
this.model
等于
this['model']
,在上述代码中,
this[model]
等于
this['genders']
this.genders