From 66e764c15a60d9b4db7e5617af260c1468ecc9a1 Mon Sep 17 00:00:00 2001 From: pgqsfrmjb <2528075388@qq.com> Date: Sun, 9 Mar 2025 11:29:25 +0800 Subject: [PATCH] ADD file via upload --- demo.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 demo.js diff --git a/demo.js b/demo.js new file mode 100644 index 0000000..3328b52 --- /dev/null +++ b/demo.js @@ -0,0 +1,47 @@ +const { createApp } = Vue; +createApp({ + data() { + return { + newTask: '', + tasks:[ + { name: 'Learn Vue', completed: false }, + { name: 'Create a Vue project with the CLI', completed: true }, + ], + editingIndex: null, + editingTask: '', + } + }, + computed: { + completedCount() { + return this.tasks.filter(task => task.completed === true).length; + } + }, + methods: { + addTask(){ + if (this.newTask.trim() !== '') { + this.tasks.push({ name: this.newTask, completed: false }); + this.newTask = ''; + } + }, + editTask(index) { + this.editingIndex = index; + this.editingTask = this.tasks[index].name; + }, + cancelEdit() { + this.editingIndex = null; + this.editingTask = ''; + }, + saveEdit(index) { + if(this.editingTask.trim() !== ''){ + this.tasks[index].name = this.editingTask; + this.cancelEdit(); + } + }, + deleteTask(index) { + this.tasks.splice(index, 1); + }, + completeTask(index) { + this.tasks[index].completed = true; + } + } +}).mount('#app');