<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- 1.引入vue -->
<script src="./vue.js"></script>
</head>
<body>
<!-- 2.创建DOM元素 -->
<div id="app">
<ul>
<!-- 在v-for遍历的元素上需要绑定key值,且key值必须是唯一的, key值的类型只能是string/number,为了高效的更新DOM节点 -->
<li v-for="(item,index) in brand" :key="item.id">
{{item.name}}
<button @click="del(index)">删除</button>
</li>
</ul>
</div>
<script>
// 3.实例化vue
let vm = new Vue({
//挂载点
el:'#app',
data:{//属性
brand:[
{id:1,name:'玛莎拉蒂'},
{id:2,name:'宝马'},
{id:3,name:'劳斯莱斯'},
{id:4,name:'奥迪'},
]
},
methods:{//方法
del(index){
this.brand.splice(index,1);
}
}
})
</script>
</body>
</html>