Reputation: 67
I try put the ajax.get in created function but i still can't get the ap_name value
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>
where is the problem?
Upvotes: 1
Views: 63
Reputation: 63059
You need to use an arrow function so that this
isn't obscured by the context of the passed function:
created: function () {
ajax.get('/envs').then((res) => {
this.apName = res.AP_NAME;
console.log(this.apName);
});
},
And you may need to change this line to:
this.apName = res.data.AP_NAME;
Upvotes: 1