文章詳情頁
javascript - vue $set 整個數組
瀏覽:103日期:2023-05-21 10:13:00
問題描述
用$set改變整個數組 應該怎么寫
data: { arr: [1,2,3,4]},methods: { fun: function(){//改變一個元素this.$set(this.arr, 2, ’a3’)//改變整個數組 應該怎么寫//this.arr = [9,8,7] }}
問題解答
回答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一般用于對象新增鍵值對,數組直接通過賦值即可,數據數據操作的話js相關操作都會有監聽。
標簽:
JavaScript
相關文章:
1. mysql - 請問數據庫字段為年月日,傳進的參數為月,怎么查詢那個月所對應的數據2. node.js - win 下 npm install 遇到了如下錯誤 會導致 無法 run dev么?3. javascript - 我的站點貌似被別人克隆了, google 搜索特定文章,除了域名不一樣,其他的都一樣,如何解決?4. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?5. [python2]local variable referenced before assignment問題6. Python2中code.co_kwonlyargcount的等效寫法7. html - 移動端radio無法選中8. php - 微信開發驗證服務器有效性9. javascript - vue+iview upload傳參失敗 跨域問題后臺已經解決 仍然報403,這是怎么回事啊?10. mysql - 如何在有自增id的情況下,讓其他某些字段能不重復插入
排行榜
