组件化思想:

组件化实现功能模块的复用

高执行效率

开发单页面复杂应用

组件状态管理(vuex)

多组件的混合使用

vue-router

代码规范

vue-router

<template>
<div>
hello info component
</div>
</template> <script>
export default {
name: "Info"
}
</script> <style scoped> </style>
<template>
<div id="app">
<div id="nav">
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link> |
<router-link to="/info">Info</router-link>
</div>
<router-view/>
</div>
</template>
export default new Router({
routes: [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/info',
name: 'info',
component: Info
},

Vuex

单向数据流概念

view actions state

Vuex多个视图依赖,菜单导航

不同视图的行为需要变更同一状态,评论弹幕

vue.js开发的状态管理模式

组件状态集中管理

import Vue from 'vue'
import Vuex from 'vuex' Vue.use(Vuex) export default new Vuex.Store({
state: { },
mutations: { },
actions: { }
})

组件的状态

改变状态的方法集

<template>
<div>
hello info component
<button type="button" @click="add()">添加</button>
</div>
</template> <script>
import store from '@/store'
export default {
name: 'Info',
store,
methods: {
add () {
console.log('dashucoding')
}
}
}
</script> <style scoped> </style>

<template>
<div class="about">
<h1>This is an about page</h1>
<p>{{msg}}</p>
</div>
</template>
<script>
import store from '@/store'
export default {
name: 'about',
store,
data () {
return {
msg: store.state.count
}
}
}
</script>
<template>
<div>
hello info component
<button type="button" @click="add()">添加</button>
</div>
</template> <script>
import store from '@/store'
export default {
name: 'Info',
store,
methods: {
add () {
console.log('dashucoding')
store.commit('increase')
}
}
}
</script> <style scoped> </style>
import Vue from 'vue'
import Vuex from 'vuex' Vue.use(Vuex) export default new Vuex.Store({
state: {
count: 0
},
mutations: {
increase () {
this.state.count++
}
},
actions: { }
})

调式

<script>
import store from '@/store'
export default {
name: 'Info',
store,
methods: {
add () {
console.log('add Event form info!')
// alert('alert form info')
debugger
store.commit('increase')
}
}
}

<template>
<div>
hello info component
<button type="button" @click="add()">添加</button>
</div>
</template> <script>
import store from '@/store'
export default {
name: 'Info',
store,
data () {
return {
msg: 'hello vue'
}
},
methods: {
add () {
console.log('dashucoding')
debugger
store.commit('increase')
},
output () {
console.log('in output')
}
}
}
</script> <style scoped> </style>

console.log

alert()

debugger

window对象绑定

<template>
<div>
hello info component
<button type="button" @click="add()">添加</button>
</div>
</template> <script>
import store from '@/store'
export default {
name: 'Info',
store,
data () {
return {
msg: 'hello vue'
}
},
mounted () {
window.vue = this
},
methods: {
add () {
console.log('dashucoding')
debugger
store.commit('increase')
},
output () {
console.log('in output')
}
}
}
</script> <style scoped> </style>

请点赞!因为你的鼓励是我写作的最大动力!

吹逼交流群:711613774

(21)打鸡儿教你Vue.js的更多相关文章

  1. (29)打鸡儿教你Vue.js

    web阅读器开发 epub格式的解析原理 Vue.js+epub.js实现一个简单的阅读器 实现阅读器的基础功能 字号选择,背景颜色 有上一页,下一页的功能 设置字号,切换主题,进度按钮 电子书目录 ...

  2. (26)打鸡儿教你Vue.js

    weex框架的使用 1.weex开发入门 2.weex开发环境搭建 3.掌握部分weex组件模块 4.了解一些vue基本常见语法 5.制作一个接近原生应用体验的app weex介绍 安装开发环境 We ...

  3. (22)打鸡儿教你Vue.js

    vue.js 单页面,多页面 Vue cli工具 复杂单页面应用Vue cli工具 交互设计,逻辑设计,接口设计 代码实现,线上测试 git clone,git int 创建分支,推送分支,合并分支 ...

  4. (19)打鸡儿教你Vue.js

    了解vue2.x的核心技术 建立前端组件化的思想 常用的vue语法 vue-router,vuex,vue-cli 使用vue-cli工具 Vue框架常用知识点 vue核心技术 集成Vue 重点看,重 ...

  5. (18)打鸡儿教你Vue.js

    介绍一下怎么安装Vue.js vue.js Vue 不支持 IE8 及以下版本,因为 Vue 使用了 IE8 无法模拟的 ECMAScript 5 特性. Vue.js是一个渐进的,可逐步采用的Jav ...

  6. (17)打鸡儿教你Vue.js

    vue-router <a class="list-group-item" v-link="{ path: '/home'}">Home</a ...

  7. (15)打鸡儿教你Vue.js

    组件化vue.js 组件单向绑定 组件双向绑定 组件单次绑定 创建组件构造器 注册组件 使用组件 Vue.extend() Vue.component() 使用组件 <div id=" ...

  8. (13)打鸡儿教你Vue.js

    一小时复习 vue.js是一个JavaScriptmvvm库,是以数据驱动和组件化的思想构建的,相比angular.js,vue.js提供了更加简洁,更加容易理解的api,如果习惯了jquery操作d ...

  9. (12)打鸡儿教你Vue.js

    组件 语法格式如下: Vue.component(tagName, options) <tagName></tagName> <div id="app" ...

随机推荐

  1. 网络编程-tcp三次握手和四次挥手

    TCP三次握手和四次挥手过程 1.三次握手 (1)三次握手的详述 首先Client端发送连接请求报文,Server段接受连接后回复ACK报文,并为这次连接分配资源.Client端接收到ACK报文后也向 ...

  2. HTML学习摘要3

    DAY 3 浏览器会自动地在标题的前后添加空行 默认情况下,HTML 会自动地在块级元素前后添加一个额外的空行,比如段落.标题元素前后. <hr /> 标签在 HTML 页面中创建水平线. ...

  3. 在angular 8中使用 less

    在angular 6中使用 less 新项目 ng new [appname] --style less 已有的项目 修改 *.css 文件及引用处后缀名为 less并在 angular.json 文 ...

  4. spring 自定义schema 加载异常 White spaces are required between publicId and systemId.

    spring 项目启动报错 报错日志如下: Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreExcepti ...

  5. linux基础命令之1

    1.创建文件夹:mkdir 文件夹名称 2.创建文件:touch  文件名称 3.编辑文件:vi 文件名称 4.保存文件::wq

  6. SpringBoot+SpringCloud+vue+Element开发项目——数据库设计

    1.用户表(sys_user) CREATE TABLE `sys_user` ( `id` ) NOT NULL AUTO_INCREMENT COMMENT '编号', `name` ) NOT ...

  7. TypeScript_基础数据类型

    TypeScript 的基础数据类型包含: string.number.boolean.array .object.null.undefined.enmu.void.never.any.tuple 注 ...

  8. 批量改主机名报错:Address 192.168.43.117 maps to bogon, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!

    ssh连接批量修改主机名报出以下提示: [root@bqh-nfs- ~]# vim modfilyhostname.sh [root@bqh-nfs- ~]# sh modfilyhostname. ...

  9. CRM-Q模糊查询

    Q查询-模糊查询 示例一 q=Q() # 实例化一个Q的对象q,我们可以给它加条件 q.children.append(("name","xxx")) # 添加 ...

  10. 下载nvidia-docker2的rpm包

    现在慢慢进入GPU的世界, 参考安装URL: https://github.com/NVIDIA/nvidia-docker # If you have nvidia-docker 1.0 insta ...