vue综合案例1-图书管理
补充知识(数组相关API)
-
变异方法(修改原有数据)
- push()
- pop()
- shift()
- unshift()
- splice()
- sort()
- reverse()
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div id="app"> <div> <span> <input type="text" v-model='fname'> <button @click='add'>添加</button> <button @click='del'>删除</button> </span> </div> <ul> <li :key='index' v-for='(item,index) in list'>{ {item}}</li> </ul> </div> <script type="text/javascript" src="./vue.js"></script> <script type="text/javascript"> // vue数组操作 var vm = new Vue({ el: '#app', data: { fname: '', list: ['apple', 'orange', 'banana'] }, methods: { add: function () { this.list.push(this.fname); this.fname = ''; }, del: function () { this.list.pop(); } } }); </script> </body> </html>
-
替换数组(生成新的数组)
- filter()
- concat()
- slice()
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div id="app"> <div> <span> <input type="text" v-model='fname'> <button @click='change'>替换</button> </span> </div> <ul> <li :key='index' v-for='(item,index) in list'>{ {item}}