<div><input v-model="newItem" v-on:keyup.enter="addNew"></div>
<div class="box-center">
<ul class="box-list">
<li v-for="item ,index in items" v-bind:class="{finished:item.isfinished}"
v-on:mouseover="moveBtn(item)" v-on:mouseout="leaveBtn(item)">
<span v-on:click="toggleFinished(item)" v-bind:class="{bgYellow:item.isBgyellow}">{{item.label}}</span>
<span class="list-btn" v-show="item.isShow">
<button v-on:click="moveUp(index,item)">上移</button>
<button v-on:click="moveDown(index,item)">下移</button>
<button v-on:click="deleteBtn(index)">删除</button>
</span>
</li>
</ul>
t;/div>
const STORAGE_KEY = 'todos-vuejs'
export default {
fetch () {
return JSON.parse(window.localStorage.getItem(
STORAGE_KEY) || '[]')
},
save (items) {
window.localStorage.setItem(STORAGE_KEY,JSON.stringify(
items))
}
}
----App.vue----
<span style="font-size:14px;"><script>
import Store from './store'
export default {
data: function() {
return {
title: 'A simple todo-list',
items: Store.fetch(),
newItem: '',
msg:'点击按钮',
isShow: false,
isBlock: true,
isBgyellow: false,
leftPx:0,
topPx:0
}
},
watch: {
items: {
handler: function(items) {
Store.save(items)
},
deep: true
}
},
methods: {
toggleFinished: function(item) {
item.isfinished = !item.isfinished
},
show:function ($event) {
$event.cancelBubble=true;
this.isBlock = false;
this.topPx = ($event.clientY);
this.leftPx = ($event.clientX);
},
stop:function(event){
this.isBlock = true;
},
moveBtn:function(item) {
// console.log(item.label)
item.isShow = true;
},
leaveBtn:function(item) {
item.isShow = false;
},
addNew: function() {
//非空才可以添加
if(this.newItem!=''){
this.items.push({
label: this.newItem,
isfinished: false
})
}
this.newItem = '';
},
moveUp:function(index,item) {
//在上一项插入该项
this.items.splice(index-1,0,(this.items[index]));
//删除后一项
this.items.splice(index+1,1);
item.isShow = false;
if(index == 0) {
alert("到顶啦!");
}
},
moveDown:function(index,item) {
//在下一项插入该项
this.items.splice(index+2,0,(this.items[index]));
// 删除前一项
this.items.splice(index,1);
item.isShow = false;
if(index == this.items.length-1) {
alert("已经是最后一项啦!");
}
},
deleteBtn:function(index) {
this.items.splice(index,1);
}
},
}
</script></span><span style="font-size: 18px;">
</span>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有