成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

javascript - vue $set 整個(gè)數(shù)組

瀏覽:144日期:2023-05-21 10:13:00

問(wèn)題描述

用$set改變整個(gè)數(shù)組 應(yīng)該怎么寫(xiě)

data: { arr: [1,2,3,4]},methods: { fun: function(){//改變一個(gè)元素this.$set(this.arr, 2, ’a3’)//改變整個(gè)數(shù)組 應(yīng)該怎么寫(xiě)//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)聽(tīng)。

標(biāo)簽: JavaScript
相關(guān)文章: