<html>
head>
script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></scriptstyle>
#app {
margin: 0px auto;
width: 500px;
border: 1px solid blue;
height: 500px;
}
.title {
line-height: 50px;
text-align: center;
height: 50px;
font-weight: 20px;
font-size: 36px;
background: coral;
}
.inp {
outline-style: none;
border: 0px solid #ccc;
width: 330px;
font-size: 15px;
padding: 3px 3px;
font-family: "Microsoft soft";
}
input:focus {
border-color: #66afe9;
outline: 0;
-webkit-box-shadow: inset 0 1px 1px rgba(0,.075),0 0 8px rgba(102,175,233,.6);
box-shadow: inset 0 1px 1px rgba(0,.6)
}
ul,li {
padding: 0;
margin: 0;
list-style: none;
}
.li-div {
text-align: center;
border: 3px solid white;
}
</>
bodydiv id="app">
class="title"
记事本
divhr>
span>
p ="color: chartreuse"请输入内容:
input type="text" placeholder="按回车保存" class="inp" v-model="tmp" @keyup.enter="add"p="content"ulli v-for="(item,index) in message">
="li-div">
>{{index}}label>{{item}}button @click="remove(index)">删除buttonliv-show="message.length>0"="float: left;"
当前记事本记录数:{{message.length}}
="float: right;;"="clear">清空
var app = new Vue({
el: '#app',data: {
tmp: "",message: ['今天好开心','今天超级棒','今天美美哒'],},methods: {
add: function () {
if (this.tmp == null || this.tmp == "") {
alert("输入不能为空");
} else {
this.message.push(this.tmp);
}
},remove: function (ind) {
var flag = confirm("是否要删除删除" + ind);
if (flag == true) {
this.message.splice(ind,1);
}
},clear: function () {
this.message = [];
},})
>