使用vue实现简单的待办事项
2024-09-07 17:36:51
待办事项
效果图
目录结构
详细代码
AddNew.vue
<template>
<div>
<input v-model="content"/>
<button @click="addList()">添加</button>
</div>
</template>
<script>
export default {
name: "AddNew",
data() {
return {
content: ''
}
},
methods: {
addList() {
if(!this.content) {
alert("请输入内容");
return;
}
//调用App.vue文件中的add方法
this.$emit("addFunc",{content: this.content});
this.content = ''
}
}
}
</script>
<style>
input {
width: 300px;
height: 30px;
border-radius: 5px;
}
button {
width: 100px;
height: 40px;
border-radius: 5px;
background: forestgreen;
color: #fff;
margin-left: 10px;
letter-spacing: 5px;
}
</style>
TheList.vue
<template>
<ol >
<li v-for="(item, index) in list" :key="index" @click="selectDel(index)">{{item.content}}</li>
</ol>
</template>
<script>
export default {
name:"TheList",
//props属性除了可以是一个数组外,还可以是一个对象
/*props: [
'list',
'flag'
],*/
props: {
list: {
type: Array,
required: true,
},
flag: {
type: Boolean,
default: true
}
},
methods: {
selectDel(index) {
if(this.flag) {
this.$emit('toDelFunc',index);
}else {
this.$emit('doDelFunc',index);
}
}
}
}
</script>
<style>
</style>
index.js
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [
]
const router = new VueRouter({
routes
})
export default router
App.vue
<template>
<div>
<h2>TodoList</h2>
<AddNew @addFunc="add"></AddNew>
<hr />
<TheList :list="toList" @toDelFunc="toDelList"></TheList>
<hr />
<TheList :list="delList" @doDelFunc="doDelList" :flag="false"></TheList>
</div>
</template>
<script>
//引入组件对象
import AddNew from './components/AddNew.vue';
import TheList from './components/TheList.vue';
export default {
data() {
return {
toList: [],
delList: []
}
},
methods: {
add(val) {
console.log(val)
this.toList.push(val);
},
toDelList(index) {
this.delList.push(this.toList.splice(index, 1)[0]);
},
doDelList(index) {
this.delList.splice(index, 1);
}
},
components: {
AddNew,
TheList
}
}
</script>
<style>
</style>
main.js
import Vue from 'vue'
import App from './App.vue'
import router from './router'
Vue.config.productionTip = false
new Vue({
router,
render: h => h(App)
}).$mount('#app')
最新文章
- java基本知识小记(1)
- html默认属性
- SpringMVC笔记
- scp 传文件
- 《算法导论》习题解答 Chapter 22.1-4(去除重边)
- mysql my.ini 详解
- openerp binary filed import export
- 【转】vim 修改tab为四个空格
- c++命名空间using
- 系统简单的UIImagePickerController
- 使用TWebBrowser组件保存网页为html和mht文件 收藏
- 微软IE11浏览器的7大变化
- 设计模式的征途—23.解释器(Interpreter)模式
- 大数据学习系列之七 ----- Hadoop+Spark+Zookeeper+HBase+Hive集群搭建 图文详解
- webstorm 支持vue element-ui 语法高亮属性自动补全
- HTML5:在移动端禁用长按选中文本功能
- macbook安装并破解Clion2018(Pycharm也一样)
- Luogu 2467[SDOI2010]地精部落 - DP
- CodeForces - 779D String Game 常规二分
- vijos &; codevs 能量项链 - 动态规划
热门文章
- Java中对象调用方法的顺序
- PL/SQL插入数据报错:Access violation at address 00413A81 in module &#39;plsqldev.exe&#39;. Read of address 00000000
- 22、oracle子查询
- 如何跟领导解释为什么选择SpringCloud alibaba作为微服务开发框架
- springBoot-Quartz快速入门
- SpringBoot Cache 深入
- 其他:Windows10安装自带的Linux
- hdu 1145(Sticks) DFS剪枝
- jenkins报错: error: insufficient permission for adding an object to repository database .git/objects
- 「NOIP2017」宝藏