【发布时间】:2019-02-05 12:39:22
【问题描述】:
我正在尝试使用 VueJS,我有以下代码:
require('./bootstrap');
window.Vue = require('vue');
window.app = new Vue({
el: '#app',
data: {
test: { }
},
methods: {
getAttributes: function(){
var pseudoThis = this;
$.get('/api/getSpecifications').done(function(resp){
pseudoThis.test = resp;
console.log(resp);
});
}
},
mounted: function(){
this.getAttributes();
}
});
ajax 调用被执行,我得到 json 结果。然而,无论我尝试什么,属性测试始终保持 {}。
有人能解释一下吗?
编辑:
做了更多的测试,还用我当前代码的副本做了一个小提琴: https://jsfiddle.net/cfhLg35v/2/
在小提琴中,一切都按预期工作,所以这似乎是一个本地问题。有人有想法吗?
【问题讨论】:
-
请执行console.log(pseudoThis) 你可能会得到关于发生了什么的提示。