<!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">
<input type="text" v-model="msg" placeholder="输入内容">
<button @click="add(msg)">添加</button>
<ul>
<li v-for="(item, index) in arr" >{{item}}===<button @click="move">删除</button></li>
</ul>
</div>
<script src="../../vue.js"></script>
<script>
const vm = new Vue({
el: '#app',
data: {
arr: ['张飞', '关羽', '刘备'],
msg:'',
},
methods: {
add() {
this.arr.push(this.msg)
},
move: function (index) {
alert('你确定要删除吗')
this.arr.splice(index, 1);
}
}
});
</script>
</body>
</html>
标签:index,arr,vue,删除,el,输入框,添加,msg
From: https://blog.csdn.net/2401_82679799/article/details/139254095