<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="js/vue.js"></script> </head> <body> <div id="app"> <h1>{{title}}</h1> <ul> <li v-for="(car, index) in cars">
我的汽车:{{car}}
<button @click="add(car)">+</button> <button @click='del(index)'>删除</button> </li> </ul> </div> <script> console.dir(Vue); const vm = new Vue({ el: '#app', data: { cars: [ { name: '奥迪',num:0}, { name: '宝马',num:1}, { name: '奔驰',num:2}, ] }, methods:{ add(car){ car.num++; }, del(i){ this.cars.splice(i,1); } } }); </script> </body> </html>