Home > Web Front-end > JS Tutorial > vue.js array update example sharing

vue.js array update example sharing

小云云
Release: 2018-03-19 16:02:13
Original
1520 people have browsed it

This article mainly shares vue.js array update examples with you, hoping to help everyone.

Change the original array

push()

pop()

shift()

unshift()

splice()

sort()

reverse()

Does not change the original array

filter()

contat()

slice()

Example:

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
            })
        }
}
Copy after login
mounted(){
   this.books.push({              //push数组方法,视图直接改变
            name:&#39;《css3实战》&#39;,
            author:&#39;huiyh&#39;
        });
        this.books=this.books.concat([{  //concat数组方法,需更新原数组
            name:&#39;《html5实战》&#39;,
            author:&#39;lala&#39;
        }])
}
Copy after login

The above is the detailed content of vue.js array update example sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template