1-1 课程介绍.mp4 vue官方文档
2-1 创建第一个Vue实例.mp4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <title > Vue 入门</title > <script src ="vue.js" > </script > </head > <body > <div id ="root" > <h1 > hello {{msg}}</h1 > </div > <script > new Vue({ el: "#root" , data: { msg: "world" } }) </script > </body > </html >
2-2 挂载点,模版与实例.mp4 挂载点、模板、实例之间的关系 vue中的el确定挂载点。 模板:挂载点里面的全部内容,可以直接写,也可以在Vue里面添加template
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <div id ="root" > </div > <script > new Vue({ el: "#root" , template: '<h1 > hello {{msg}} </h1 > ', data: { msg: "world" } }) </script >
2-3 Vue实例中的数据,事件和方法.mp4 插值表达式
a在 new Vue({data: {a: 123}}) 中定义
1 2 3 4 5 <h1 > {{a}}</h1 > 使用a-text也可实现同样的效果 <h1 a-text ="a" > </h1 > 或 <h1 a-html ="content" > </h1 >
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 <!DOCTYPE html > <html lang ="en" xmlns:v-on ="http://www.w3.org/1999/xhtml" > <head > <meta charset ="UTF-8" > <title > Vue 入门</title > <script src ="vue.js" > </script > </head > <body > <div id ="root" @click ="handleClick" > {{msg}} </div > <script > new Vue({ el: "#root" , data: { msg: "world" }, methods:{ handleClick: function () { this .msg="hello" ; } } }) </script > </body > </html >
2-4 Vue中的属性绑定和双向数据绑定.mp4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 <!DOCTYPE html > <html lang ="en" xmlns:v-on ="http://www.w3.org/1999/xhtml" > <head > <meta charset ="UTF-8" > <title > Vue 入门</title > <script src ="vue.js" > </script > </head > <body > <div id ="root" > <div title ="this is title1" > hello world</div > <div :title ="title" > hello world</div > <input v-model ="content" > <div > {{content}}</div > </div > <script > new Vue({ el: "#root" , data: { msg: "world" , title: "this is title2" , content: "content" }, methods:{ } }) </script > </body > </html >
2-5 Vue中的计算属性和侦听器.mp4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 <!DOCTYPE html > <html lang ="en" xmlns:v-on ="http://www.w3.org/1999/xhtml" > <head > <meta charset ="UTF-8" > <title > Vue 入门</title > <script src ="vue.js" > </script > </head > <body > <div id ="root" > 姓: <input v-model ="firstName" > 名: <input v-model ="lastName" > <div > {{firstName}} {{lastName}}</div > <div > {{fullName}}</div > <div > {{count}}</div > </div > <script > new Vue({ el: "#root" , data: { firstName: '' , lastName: '' , count: 0, }, computed:{ fullName: function () { return this .firstName + ' ' + this .lastName } }, watch: { lastName: function () { this .count ++; }, firstName: function () { this .count ++; } }, methods:{ } }) </script > </body > </html >
2-6 v-if, v-show与v-for指令.mp4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 <!DOCTYPE html > <html lang ="en" xmlns:v-on ="http://www.w3.org/1999/xhtml" > <head > <meta charset ="UTF-8" > <title > Vue 入门</title > <script src ="vue.js" > </script > </head > <body > <div id ="root" > <div v-if ="show" > hello world</div > <div v-show ="show" > hello world</div > <button @click ="toggle" > toggle</button > <ul > <li v-for ="item of list" > {{item}}</li > <li v-for ="(item, index) of list" key ="index" > {{index}} {{item}}</li > </ul > </div > <script > new Vue({ el: "#root" , data: { show: true , list: [1, 1, 3, 4, 5], }, computed:{ }, watch: { }, methods:{ toggle: function () { this .show = !this .show } } }) </script > </body > </html >
3-1 todolist功能开发.mp4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 <!DOCTYPE html > <html lang ="en" xmlns:v-on ="http://www.w3.org/1999/xhtml" > <head > <meta charset ="UTF-8" > <title > Vue 入门</title > <script src ="vue.js" > </script > </head > <body > <div id ="root" > <div > <input v-model ="thing" > <button @click ="submit" > submit</button > </div > <ul > <li v-for ="item of list" > {{item}}</li > </ul > </div > <script > new Vue({ el: "#root" , data: { thing: "" , list: [], }, computed:{ }, watch: { }, methods:{ submit: function () { if (this .thing.trim()==="" ) return ; this .list.push(this .thing); this .thing = "" ; } } }) </script > </body > </html >
3-2 todolist组件拆分-1.5.mp4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 <!DOCTYPE html > <html lang ="en" xmlns:v-on ="http://www.w3.org/1999/xhtml" > <head > <meta charset ="UTF-8" > <title > Vue 入门</title > <script src ="vue.js" > </script > </head > <body > <div id ="root" > <div > <input v-model ="thing" > <button @click ="submit" > submit</button > </div > <ul > <todo-item v-for ="(item, index) of list" :key ="index" :content ="item" > 全局组件</todo-item > </ul > </div > <script > Vue.component('todo-item' , { props: ['content' ], template: '<li > {{content}} </li > ' }); // template: '<li > item</li > ' new Vue({ el: "#root" , data: { thing: "" , list: [], }, computed:{ }, watch: { }, methods:{ submit: function () { if (this .thing.trim()==="" ) return ; this .list.push(this .thing); this .thing = "" ; } } }) </script > </body > </html >
3-3 组件与实例的关系.mp4 组件也是实例, 也可以添加methods data等属性 new Vue(){} 实例中的template属性没有定义时,为挂载点下的HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 // 注册后即可直接在HTML中使用 Vue.component('todo-item', { // 1. 定义属性 props: ['content'], // 2. 使用属性 template: '<li @click ="itemClicked" > {{content}}</li > ', methods: { itemClicked: function () { alert('clicked'); } } });
3-4 实现todolist的删除功能.mp4 组件之间通过属性传递值
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 <!DOCTYPE html > <html lang ="en" xmlns:v-on ="http://www.w3.org/1999/xhtml" > <head > <meta charset ="UTF-8" > <title > Vue 入门</title > <script src ="vue.js" > </script > </head > <body > <div id ="root" > <div > <input v-model ="thing" > <button @click ="submit" > submit</button > </div > <ul > <todo-item v-for ="(item, index) of list" :key ="index" :content ="item" :index ="index" @delete ="handleDelete" > 全局组件</todo-item > </ul > </div > <script > Vue.component('todo-item' , { props: ['content' , 'index' ], template: '<li @click ="itemClicked" > {{content}} </li > ', methods: { itemClicked: function () { this .$emit("delete" , this .index); } } }); new Vue({ el: "#root" , data: { thing: "" , list: [], }, computed:{ }, watch: { }, methods:{ submit: function () { if (this .thing.trim()==="" ) return ; this .list.push(this .thing); this .thing = "" ; }, handleDelete: function (index) { this .list.splice(index, 1 ); } } }) </script > </body > </html >
4-1 vue-cli的简介与使用-1.5.mp4 https://cli.vuejs.org/zh/ npm install -g @vue/cli npm install -g @vue/cli-init
1 2 3 4 5 6 7 8 9 10 11 12 13 ➜ WebstormProjects vue init webpack todolist ? Project name todolist ? Project description A Vue.js project ? Author ? Vue build standalone ? Install vue-router? No ? Use ESLint to lint your code? Yes ? Pick an ESLint preset Standard ? Set up unit tests No ? Setup e2e tests with Nightwatch? No ? Should we run `npm install` for you after the project has been created? (recom mended) npm
To get started:
cd todolist npm run dev
components: {App} // {‘App’: App} 键值相等可简写 单文件组件 app.vue template script style 3个标签 template 下只可有一个元素
网页自动刷新
4-2 使用vue-cli开发TodoList.mp4 npm run dev 执行的命令定义在package.json scripts中
4-3 全局样式与局部样式.mp4 1 2 3 4 scoped : 局部的样式 <style scoped > </style >
4-4 课程总结-1.5.mp4