diff --git a/20_脚手架/vue_code/15.src_todolist添加编辑逻辑/App.vue b/20_脚手架/vue_code/15.src_todolist添加编辑逻辑/App.vue
new file mode 100644
index 0000000..ddfd312
--- /dev/null
+++ b/20_脚手架/vue_code/15.src_todolist添加编辑逻辑/App.vue
@@ -0,0 +1,145 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/20_脚手架/vue_code/15.src_todolist添加编辑逻辑/main.js b/20_脚手架/vue_code/15.src_todolist添加编辑逻辑/main.js
new file mode 100644
index 0000000..4d5e394
--- /dev/null
+++ b/20_脚手架/vue_code/15.src_todolist添加编辑逻辑/main.js
@@ -0,0 +1,19 @@
+// 引入Vue
+import Vue from "vue";
+// 引入App
+import App from "./App";
+
+// 设置Vue
+Vue.config.productionTip = false
+
+
+// 实例化Vue
+new Vue({
+ components: {
+ App
+ },
+ render: h => h(App),
+ beforeCreate() {
+ Vue.prototype.$bus = this // 安装全局事件总线
+ }
+}).$mount('#app')
diff --git a/20_脚手架/vue_code/src/App.vue b/20_脚手架/vue_code/src/App.vue
index 2bdf923..ddfd312 100644
--- a/20_脚手架/vue_code/src/App.vue
+++ b/20_脚手架/vue_code/src/App.vue
@@ -50,6 +50,13 @@ export default {
this.todos = this.todos.filter(todo => todo.id !== id)
},
+ // 更新一个TodoItem
+ updateTodo(id, title) {
+ this.todos.forEach((todo) => {
+ if (todo.id === id) todo.title = title
+ })
+ },
+
// 勾选或取消勾选全部todo任务,绑定到TodoBottom中
checkAllTodo(done) {
this.todos.forEach((todo) => todo.done = done)
@@ -73,13 +80,13 @@ export default {
// 生成全局事件总线
mounted() {
this.$bus.$on('checkTodo', this.checkTodo)
- // this.$bus.$on('deleteTodo', this.deleteTodo)
+ this.$bus.$on('updateTodo', this.updateTodo)
this.pubId = pubsub.subscribe('itemDel', this.deleteTodo) // 使用订阅方式实现删除功能
},
// 销毁全局事件总线
beforeDestroy() {
this.$bus.$off('checkTodo')
- // this.$bus.$off('deleteTodo')
+ this.$bus.$off('updateTodo')
this.pubsub.unsubscribe(this, pubId) // 使用订阅方式实现删除功能,销毁订阅
}
}
@@ -109,6 +116,13 @@ body {
border: 1px solid #bd362f;
}
+.btn-edit {
+ color: #fff;
+ background-color: skyblue;
+ border: 1px solid #82cdea;
+ margin-right: 5px;
+}
+
.btn-danger:hover {
color: #fff;
background-color: #bd362f;
diff --git a/20_脚手架/vue_code/src/components/TodoItem.vue b/20_脚手架/vue_code/src/components/TodoItem.vue
index 8aa3ac4..027b8fe 100644
--- a/20_脚手架/vue_code/src/components/TodoItem.vue
+++ b/20_脚手架/vue_code/src/components/TodoItem.vue
@@ -2,9 +2,11 @@