<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<style>
*{
margin: 0;
padding: 0;
}
table{
width: 350px;
}
tr>td{
width: 50%;
border: 1px solid;
text-align: center;
padding: 8px 0;
}
</style>
<title>简易留言板</title>
</head>
<body>
<div id="box">
<input type="text" v-model="msg">
<input type="button" @click="fn" value="提交">
<table>
<tr v-for="(item,index) in arr" :key="index">
<td>{{ item }}</td>
<td><button @click="del(index)">删除</button></td>
</tr>
</table>
</div>
</body>
</html>
<script>
new Vue({
el : "#box",
data: {
msg : '',
arr : []
},
methods: {
fn(){
this.arr.unshift(this.msg);
this.msg = "";
},
del(index){
this.arr.splice(index,1);
}
},
})
</script>
网友评论