好啊我不是一个完全的新手,确实有一些Vue xp,但这让我感到困扰.我错过了什么明显的东西.
我在一个挂载的方法中通过ajax调用加载了一个对象:
job: {
"title": "value",
"location": {
"name":"HONG KONG"
}
}
当我给{job.title}打电话时,一切都很好.当我调用{job.location.name}时,我有一个未定义的错误,但该值呈现.当我调用{job.location}时,我得到了json对象,因此它被定义.
啊!我相信这真的很简单,但我不明白为什么这不是应该的那么简单.
//额外的
这是我的整个Vue课程
const router = new VueRouter({
mode: 'history',
routes: []
});
const app = new Vue( {
router,
el: '#app',
data: {
job: {}
},
mounted: function () {
var vm = this
jQuery.ajax({
url: 'https://xxx' + this.jobId,
method: 'GET',
success: function (data) {
vm.job = data;
},
error: function (error) {
console.log(error);
}
});
},
computed: {
jobId: function() {
return this.$route.query.gh_jid
}
}
})