我尝试将ajax.get放入创建的函数中,但仍然无法获得ap_name值
vue.js
created: function () {
ajax.get('/envs').then(function (res) {
this.apName = res.AP_NAME;
console.log(this.apName);
});
},
html
<a :href="`${apName}/home`"</a>
哪里有问题?
您需要使用箭头函数,以免this
被传递的函数的上下文所遮挡:
created: function () {
ajax.get('/envs').then((res) => {
this.apName = res.AP_NAME;
console.log(this.apName);
});
},
您可能需要将此行更改为:
this.apName = res.data.AP_NAME;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句