【发布时间】:2021-01-19 22:11:35
【问题描述】:
我想将API结果中的值发送到数据时出现错误,错误是这样的
Uncaught (in promise) TypeError: Cannot set property 'notification' of undefined at eval (HeaderPortal.vue?070f:367)
这是我的 HeaderPortal.vue
data() {
return {
notification: []
}
}
methods: {
const res = this.GET('/api/v2/notification', 'BEARER', null).then( function(res) {
console.log(JSON.parse(res))
this.notification = JSON.parse(res);
});
}
this.GET 来自这里
methods: {
async GET(url, headers, callback) {
const options = headers === 'BASIC' ? HEADERS_BASIC : HEADERS_BEARER;
try {
const response = await axios.get(`${BASE_URL}${url}`, options);
return (JSON.stringify(response));
} catch (e) {
console.error(e);
}
},
}
如何处理?我的代码有问题吗?
【问题讨论】:
标签: nuxt.js