本文主要和大家分享vue.js陣列更新實例,希望能幫助大家。
改變原始陣列
push()
pop()
shift()
unshift()
splice()
sort()
reverse()
#不改變原始陣列
filter()
contat()
slice()
實例:
1 2 3 4 5 6 7 8 9 10 11 12 | computed:{
filterBooks(){
return this.books.filter( function (book){
return book.name.match(/javascript/)
})
},
sortBooks(){
return this.lists.sort( function (a,b) {
return a.name.length<b.name.length
})
}
}
|
登入後複製
1 2 3 4 5 6 7 8 9 10 | mounted(){
this.books.push({
name:'《css3实战》',
author:'huiyh'
});
this.books=this.books.concat([{
name:'《html5实战》',
author:'lala'
}])
}
|
登入後複製
以上是vue.js數組更新實例分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!