vuejs2.0 数组操作 提示Cannot read property 'push' of undefined
生活随笔
收集整理的這篇文章主要介紹了
vuejs2.0 数组操作 提示Cannot read property 'push' of undefined
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
想做一個數組添加的操作
methods方法中
this.imglist 在data中定義的數組
data() {const self = thisreturn {//作品數組imglist: [], 本來以為 定義了個全局的self ,就可以用,但是還是報錯 push 未定義 發現沒有聲明this 指向的時候,this并不是指向的vue的,所以沒有找到this.imaglisyt 的push這個方法,自然就沒有push這個屬性了所以就必須 要設置 this的指向, var _this=this; //this指向vue (rst.data.works.dataList).forEach(function(value,index){_this.imglist.push(value);})總結
以上是生活随笔為你收集整理的vuejs2.0 数组操作 提示Cannot read property 'push' of undefined的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Objective-c中的占位符,打印B
- 下一篇: 计算机考研1000题pdf,2020考研