57 lines
1.4 KiB
HTML
57 lines
1.4 KiB
HTML
<!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">
|
|
<title>Document</title>
|
|
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
|
|
</head>
|
|
<body>
|
|
|
|
|
|
<div id="app">
|
|
<input type="text" placeholder="请输入便签内容" v-model="UserMessage">
|
|
<button @click="addList">提交</button>
|
|
<div v-if="listData.length==0">
|
|
暂无便签内容...
|
|
</div>
|
|
<ul v-else>
|
|
<li v-for="(item,index) in listData">
|
|
{{ index+1 }} : {{item}}
|
|
<span @click="deleteList(index)"> x </span>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<script>
|
|
new Vue({
|
|
el: '#app',
|
|
data: {
|
|
listData: [],
|
|
UserMessage: null
|
|
},
|
|
mounted () {
|
|
this.listData = this.getLocalStorage("localData")
|
|
},
|
|
methods: {
|
|
addList () {
|
|
this.listData.push(this.UserMessage)
|
|
this.setLocalStorage(this.listData)
|
|
this.UserMessage = null
|
|
},
|
|
deleteList(index) {
|
|
this.listData.splice(index,1)
|
|
this.setLocalStorage(this.listData)
|
|
},
|
|
getLocalStorage(key) {
|
|
return JSON.parse(localStorage.getItem(key))
|
|
},
|
|
setLocalStorage(value) {
|
|
localStorage.setItem("localData",JSON.stringify(value))
|
|
}
|
|
},
|
|
})
|
|
</script>
|
|
</body>
|
|
</html> |