Vue3 开发 Todolist 教程

本文状态:未完成 一、产品原型 参考 Windows todo设计一个简单的移动端todo页面原型 二、开发教程 1、新建Todolist.vue 先通过脚手架配置好vue项目:@vue/cli 在项目src\views下面新建Todo.vue <template> <div class="todo"> <h1>Todolist</h1> <input type="text" v-model="content" @keypress="add"><button @click="add">Add</button> <p>{{content}}</p> <div class="section-title">待办</div> <ul class="todolist underway"> <TodoItem :="todo" v-for="todo in underway" :key="todo.id" :class="{done:todo.status}" v-model="todo.status" /> </ul> <div class="section-title">已完成</div> <ul class="todolist completed"> <TodoItem :="todo" v-for="todo in completed" :key="todo.id" :class="{done:todo.status}" v-model="todo.status" /> </ul> </div> </template> <script> import TodoItem from '../components/TodoItem'; export default { name: "Todo", components:{ TodoItem }, data(){ return{ content:'hello world!', checked:'', todos:[ { id:1, content:'这是内容1', status:false }, { id:2, content:'这是内容2', status:true }, { id:3, content:'这是内容3', status:true }, { id:4, content:'这是内容4', status:false }, { id:5, content:'这是内容5', status:true } ], } }, methods:{ add(){ this.todos.push({ id:this.todos.length+1, content:this.content, status:false }) } }, computed:{ underway(){ return this.todos.filter(todos=>!todos.status); }, completed(){ return this.todos.filter(todos=>todos.status); } } } </script> <style scoped> .section-title{font-weight: bold;font-size: 18px;} .todolist li{list-style: none;} .todolist li.done{text-decoration:line-through; } </style> 2、添加组件 <template> <li> <input type="checkbox" :name="id" :id="id" :value="content" :checked="modelValue" @input="onInput"/> <label :for="id">{{content}}</label> </li> </template> <script> export default { name: "TodoItem", data(){ return{ } }, props:{ id:Number, content:String, modelValue:Boolean }, methods:{ onInput(e){ this.$emit('update:modelValue',e.target.checked); } } } </script> <style scoped> </style> 2、添加路由 router\index.js中添加 ...

November 10, 2020 · 2 min · 332 words · Aixin.me

Vue3.2 组合式API基础知识点

本页内容基于VUE3.2版本,且以组合式API模式编写<script setup> 推荐的 IDE 配置是 Visual Studio Code + Volar 扩展 中文文档:https://staging-cn.vuejs.org/ 使用Vite安装Vue npm init vite@latest <project-name> -- --template vue # 或者 npm create vite@latest <project-name> -- --template vue cd <project-name> npm install npm run dev 模板语法 // 显示文本 <span>Message: {{ msg }}</span> // 显示原始HTML <p>Using v-html directive: <span v-html="rawHtml"></span></p> // 绑定HTML属性 <div v-bind:id="dynamicId"></div> // 绑定多个HTML属性 <div v-bind="objectOfAttrs"></div> // 调用函数 <span :title="toTitleDate(date)"> {{ formatDate(date) }} </span> // 绑定动态参数 <a v-bind:[attributeName]="url"> ... </a> <a v-on:[eventName]="doSomething"> ... </a> // 如果需要操作['foo' + bar],建议使用计算属性 // 修饰符 <form @submit.prevent="onSubmit">...</form> // 绑定多个HTML属性 const objectOfAttrs = { id: 'container', class: 'wrapper' } 简写: ...

November 5, 2020 · 3 min · 620 words · Aixin.me