我得到'无法读取未定义的属性推送'错误:这是我的vueJs代码:
data:{
CoIsignedListUID:[]
}
methods:{
fetchCoISigned: function () {
this.$http.get('/cimsm/public/api/fetchCoIsigned/' + this.conflictofInterest.complaintID).then(function (response) {
var data = response.data;
this.$set('CoIsignedList', data);
data.forEach(function (detail) {
this.CoIsignedListUID.push(detail.uID);
});
});
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?谢谢
gur*_*het 10
this.CoIsignedListUID
没有定义
可能是因为this
不是this
你认为的那样
你应该做
var _this = this
Run Code Online (Sandbox Code Playgroud)
在功能之外然后
_this.CoIsignedListUID.push(detail.uID);
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用ES2015箭头语法.
代替:
.then(function (response) {}
Run Code Online (Sandbox Code Playgroud)
使用:
.then((response) => {}
Run Code Online (Sandbox Code Playgroud)
'this'现在可在函数内部使用,因此无需创建新变量.详细信息在这里.
归档时间: |
|
查看次数: |
16539 次 |
最近记录: |