文章詳情頁(yè)
javascript - vue $set 整個(gè)數(shù)組
瀏覽:149日期:2023-05-21 10:13:00
問(wèn)題描述
用$set改變整個(gè)數(shù)組 應(yīng)該怎么寫
data: { arr: [1,2,3,4]},methods: { fun: function(){//改變一個(gè)元素this.$set(this.arr, 2, ’a3’)//改變整個(gè)數(shù)組 應(yīng)該怎么寫//this.arr = [9,8,7] }}
問(wèn)題解答
回答1:直接賦值this.arr = [’h’, ’e’, ’...’];
回答2:methods: { fun() {this.$set(this, arr, [’a’, ’b’, ’c’]) }, fun2() {this.arr = [’a’, ’b’, ’c’] }, fun3() {this.arr.splice(0, this.arr.length, ’a’, ’b’, ’c’) }}回答3:
$set一般用于對(duì)象新增鍵值對(duì),數(shù)組直接通過(guò)賦值即可,數(shù)據(jù)數(shù)據(jù)操作的話js相關(guān)操作都會(huì)有監(jiān)聽。
標(biāo)簽:
JavaScript
相關(guān)文章:
1. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””2. Span標(biāo)簽3. css - 求推薦適用于vue2的框架 像bootstrap這種類型的4. docker-machine添加一個(gè)已有的docker主機(jī)問(wèn)題5. java - Collections類里的swap函數(shù),源碼為什么要新定義一個(gè)final的List型變量l指向傳入的list?6. css - 關(guān)于div自適應(yīng)問(wèn)題,大家看圖吧,說(shuō)不清7. android新手一枚,android使用httclient獲取服務(wù)器端數(shù)據(jù)失敗,但是用java工程運(yùn)行就可以成功獲取。8. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問(wèn)題。9. redis啟動(dòng)有問(wèn)題?10. SessionNotFoundException:會(huì)話ID為null。調(diào)用quit()后使用WebDriver嗎?(硒)
排行榜

熱門標(biāo)簽