【发布时间】:2018-10-06 00:03:32
【问题描述】:
我正在尝试制作一个待办事项应用程序,但我不知道如何使用 Vue 制作本地存储。 我的 App.vue 看起来像这样:
这里的代码来自 TodoList.vue,用于删除和完成任务。我还有两个组件用于编辑任务和发布新任务。也许 localstorage 方法应该在 CreatingTodo.vue 中?我安装了 npm install vue-localstorage --save 但从现在开始我不知道在哪里以及如何继续存储。
<template>
<div>
<p class="tasks">Completed Tasks: {{todos.filter(todo => {return todo.done === true}).length}}</p>
<p class="tasks">Pending Tasks: {{todos.filter(todo => {return todo.done === false}).length}}</p>
<todo v-on:delete-todo="deleteTodo" v-on:complete-todo="completeTodo" v-for="todo in todos" :todo.sync="todo"></todo>
</div>
</template>
<script type = "text/javascript" >
import sweetalert from 'sweetalert';
import Todo from './Todo';
export default {
props: ['todos'],
components: {
Todo,
},
methods: {
deleteTodo(todo) {
sweetalert({
title: 'Are you sure?',
text: 'This To-Do will be permanently deleted!',
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Yes, delete it!',
closeOnConfirm: false,
},
() => {
const todoIndex = this.todos.indexOf(todo);
this.todos.splice(todoIndex, 1);
sweetalert('Deleted!', 'Your To-Do has been deleted.', 'success');
});
},
completeTodo(todo) {
const todoIndex = this.todos.indexOf(todo);
this.todos[todoIndex].done = true;
sweetalert('Success!', 'To-Do completed!', 'success');
},
},
};
</script>
<style scoped>
p.tasks {
text-align: center;
}
</style>
我的第二个问题也是关于 Vue。因为直到现在我还在用 HTML、CSS 和 JavaScript 编写我的大学项目。我如何连接这两个项目这个 todo 是 localhost:8080 而项目的另一部分只是本地路径。提前谢谢你!
欢迎任何建议!
【问题讨论】:
-
在发布新问题之前请先搜索 :) 另外,请在每个帖子中提出一个问题。提示:您的第二个问题可能已经在另一篇文章中得到解答。
-
@Boaz,非常感谢。我会牢记在心,以备不时之需。我道歉:)
标签: javascript html vue.js vuejs2