成果图~
下面是代码 记得要引入vue.js和boostrap.css地址
<!DOCTYPE html>
<html >
<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">
<title>泡泡大魔王的留言栏</title>
<link rel="stylesheet" href="./bootstrap.min.css" target="_blank" rel="external nofollow" />
<script src="../js/vue.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
li {
list-style: none;
}
ul li {
width: 100%;
}
body {
background: #999;
}
form {
width: 600px;
margin: 20px auto;
}
.txt {
margin-bottom: 30px;
}
.text {
font: 16px/20px "宋体";
margin-bottom: 15px;
}
.form-group {
text-align: center;
}
.panel-body {
width: 600px;
}
</style>
</head>
<body>
<!--v-show='布尔值'-->
<form id="lovetalk">
<div class="form-group">
<h2>{{master}}的留言板</h2>
<input type="text" class="form-control txt" placeholder="username" v-model="username">
<textarea class="form-control text" rows="3" placeholder="请输入您要留言的内容"
@input="content=$event.target.value"></textarea>
<button type="button" class="btn btn-primary btn-lg" style="width:100%" @click="add">立即提交</button>
</div>
<ul>
<li v-for="(item,index) of list">
<div class="panel panel-default">
<div class="panel-heading">{{item.name}}</div>
<div class="panel-body">
{{item.content}}
<div class="button-group">
<button type="button" @click="remove(index)" class="btn btn-danger pull-right"
style="margin-left:5px;" @click="remove(index)">删除</button>
<button type="button" @click="change(index,'qq')"
class="btn btn-info pull-right">修改</button>
</div>
</div>
</div>
</li>
</ul>
<button type="button" v-show="list.length!==0" class="alert alert-danger" role="alert" style="width:100%"
@click="clear">
清空全部留言
</button>
</form>
<script>
let vm = new Vue({
el: '#lovetalk',
data: {
master: "泡泡大魔王",
username: "泡泡",
content: "泡泡无敌大铁拳!",
list: [
{ id: 1, name: '张三', content: '在么' },
{ id: 2, name: '李四', content: '直接说事,我好知道我在不在' }
]
},
methods: {//vue的函数方法组就只能叫methods不能改名字
add() {
if (this.username && this.content) {
this.list.push({
id: this.list.length + 1,
name: this.username,
content: this.content
})
} else {
alert("请输入正确的留言")
}
},
remove(index) {
this.list.splice(index, 1)
},
change(index) {
var val = prompt("请输入您要更改的内容");
this.list[index].content = val;
},
clear() {
this.list = [];
}
}
}
)
</script>
</body>
</html>
感悟:boosrtap好麻烦找了好久没有看到中意的,希望能熟练再用吧