(21)打鸡儿教你Vue.js
组件化思想:
组件化实现功能模块的复用
高执行效率
开发单页面复杂应用
组件状态管理(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的更多相关文章
- (29)打鸡儿教你Vue.js
web阅读器开发 epub格式的解析原理 Vue.js+epub.js实现一个简单的阅读器 实现阅读器的基础功能 字号选择,背景颜色 有上一页,下一页的功能 设置字号,切换主题,进度按钮 电子书目录 ...
- (26)打鸡儿教你Vue.js
weex框架的使用 1.weex开发入门 2.weex开发环境搭建 3.掌握部分weex组件模块 4.了解一些vue基本常见语法 5.制作一个接近原生应用体验的app weex介绍 安装开发环境 We ...
- (22)打鸡儿教你Vue.js
vue.js 单页面,多页面 Vue cli工具 复杂单页面应用Vue cli工具 交互设计,逻辑设计,接口设计 代码实现,线上测试 git clone,git int 创建分支,推送分支,合并分支 ...
- (19)打鸡儿教你Vue.js
了解vue2.x的核心技术 建立前端组件化的思想 常用的vue语法 vue-router,vuex,vue-cli 使用vue-cli工具 Vue框架常用知识点 vue核心技术 集成Vue 重点看,重 ...
- (18)打鸡儿教你Vue.js
介绍一下怎么安装Vue.js vue.js Vue 不支持 IE8 及以下版本,因为 Vue 使用了 IE8 无法模拟的 ECMAScript 5 特性. Vue.js是一个渐进的,可逐步采用的Jav ...
- (17)打鸡儿教你Vue.js
vue-router <a class="list-group-item" v-link="{ path: '/home'}">Home</a ...
- (15)打鸡儿教你Vue.js
组件化vue.js 组件单向绑定 组件双向绑定 组件单次绑定 创建组件构造器 注册组件 使用组件 Vue.extend() Vue.component() 使用组件 <div id=" ...
- (13)打鸡儿教你Vue.js
一小时复习 vue.js是一个JavaScriptmvvm库,是以数据驱动和组件化的思想构建的,相比angular.js,vue.js提供了更加简洁,更加容易理解的api,如果习惯了jquery操作d ...
- (12)打鸡儿教你Vue.js
组件 语法格式如下: Vue.component(tagName, options) <tagName></tagName> <div id="app" ...
随机推荐
- openwrt luci web分析
openwrt luci web分析 来源 https://www.jianshu.com/p/596485f95cf2 www/cbi-bin/luci #!/usr/bin/lua --cgi的执 ...
- android RecyclerView的Linear布局案例
1.先创建 activity_recycle_view.xml 和 activity_recycler_linear_item.xml 如下: <?xml version="1.0&q ...
- Go strconv模块:字符串和基本数据类型之间转换
本文转自Golove博客:http://www.cnblogs.com/golove/p/3262925.html ParseBool 将字符串转换为布尔值 // 它接受真值:1, t, T, TRU ...
- 如何打包ANE
来源:http://blog.sina.com.cn/s/blog_6471e1bb01012aql.html 首先先说一下打包ANE必须的部件: 1.ActionScript扩展库SWC 2.本机扩 ...
- Topshelf+Quartz实现windows任务
Topshelf使用示例, HostFactory.Run(x => { x.Service<QuartzStartup>(s => { s.ConstructUsing(na ...
- Python学习日记(十六) time模块和random模块
time模块 python表示时间的三种方式:时间戳.元祖(struct_time).格式化时间字符串 三种格式之间的转换: 1.时间戳 就是从1970年1月1日0点0分0秒开始按秒计算的偏移量,时间 ...
- Git-fatal:remote error:You can't push to git://github.com/username/*.git use https:
注意不是git://github.com/cs942651107/TestCode.git 一个:一个@协议不一样,:的不能push 关联远程库git remote add origin git ...
- 基于NFS的PV动态供给(StorageClass)
一.简介 PersistentVolume(PV)是指由集群管理员配置提供的某存储系统上的段存储空间,它是对底层共享存储的抽象,将共享存储作为种可由用户申请使的资源,实现了“存储消费”机制.通过存储插 ...
- Linux下环境变量设置 (转)
Linux下环境变量设置 1.在Windows 系统下,很多软件安装都需要配置环境变量,比如 安装 jdk ,如果不配置环境变量,在非软件安装的目录下运行javac 命令,将会报告找不到文件,类似的错 ...
- python之变量的数据类型(3)dict 及解构简单介绍
一.变量的数据类型(3) 1. dict 字典dict 用{}来表示 键值对数据 {key:value} 唯一性 键 都必须是可哈希的 不可变的数据类型就可以当做字典中的键 值 没有任何限制 2.增删 ...