(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" ...
随机推荐
- logback 日志相关
日志相关: logback:https://www.cnblogs.com/gavincoder/p/10091757.html https://www.cnblogs.com/hhhshct/p/9 ...
- MySQL数据库连接报错
数据库版本8.x和其他版本配置有区别: 1. 驱动依赖和连接 报错: Could not create connection to database server - java mysql conne ...
- js实现用户输入日期算出是今年的第几天
const rs = require("readline-sync"); // 根据用户输入的年月日输出第几天 // 欢迎 console.log("欢迎来到查询系统&q ...
- 分享linux系统more基本命令python源码
此python源码是linux系统more基本命令的实现. 实现linux中more的基本功能,当more后加一个文件名参数时候,分屏显示按空格换页,按回车换行',在左下角显示百分比; 以处理管道参数 ...
- C# Microsoft.Office 操作Excel总结
1.导入命名空间: using Microsoft.Office.Interop.Excel; 2.如何打开已有excel文档,或者创建一个新的excel文档 Application app = ...
- Objective-C学习笔记 利用协议实现回调函数
来源:http://mobile.51cto.com/iphone-278354.htm Objective-C学习笔记 利用协议实现回调函数是本文要介绍的内容,主要是实现一个显示文字为测试的视图,然 ...
- Redis数据结构和使用场景,redis内存淘汰策略
什么样的数据适合放入Redis? sql执行耗时特别久,且结果不频繁变动的数据,适合放入Redis. Redis是单线程的,为什么会这么快? 纯内存操作 单线程操作,避免频繁的上下文切换 采用了非阻塞 ...
- arm9的中断
GPIO 习惯了stm32的GPIO,发现高端处理器arm在这方面反而简单了. ARM9控制GPIO只有三种寄存器. GPxCON:配置引脚功能,GPACON用一位控制一个GPIO,分别是0为输出引脚 ...
- django使用admin站点上传图片
Django有提供文件系统支持,在Admin站点中可以轻松上传图片.使用Admin站点保存图片,需要安装Python的图片操作包 pip install Pillow 1 配置 默认情况下,Dja ...
- centos7 安装Virtualenv
若想在同一个服务器上,存在多个不同的解析器版本,使用虚拟环境 1.安装虚拟环境 pip3 install virtualenv 2.创建虚拟环境 virtualenv --no-site-packag ...