博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vue2
阅读量:4349 次
发布时间:2019-06-07

本文共 1593 字,大约阅读时间需要 5 分钟。

src    main.js    App.vue    store        actions.js        actions.js        index.js        mutations.js        types.js

main.js

import Vue from 'vue'import App from './App.vue'import store from './store/'new Vue({	store,	el: '#app',	render: h => h(App)})

 App.vue

 action.js

import * as types from './types'export default {	increment: ({		commit	}) => {		commit(types.INCREMENT);	},	decrement: ({		commit	}) => {		commit(types.DECREMENT);	},	clickOdd: ({		commit,		state	}) => {		if (state.mutations.count % 2 == 0) {			commit(types.INCREMENT);		}	},	clickAsync: ({		commit	}) => {		new Promise((resolve) => {			setTimeout(function() {				commit(types.INCREMENT);			}, 1000);		})	}}

 getters.js

export default {	count: (state) => {		return state.count;	},	getOdd: (state) => {		return state.count % 2 == 0 ? '偶数' : '奇数'	}}

 index.js

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

 mutation.js

import {	INCREMENT,	DECREMENT} from './types'import getters from './getters'const state = {	count: 20};const mutations = {	[INCREMENT](state) {		state.count++;	},	[DECREMENT](state) {		state.count--;	}};export default {	state,	mutations,	getters}

 types.js

export const INCREMENT = 'INCREMENT';export const DECREMENT = 'DECREMENT';

 

转载于:https://www.cnblogs.com/yaowen/p/7072363.html

你可能感兴趣的文章
关于render函数的总结
查看>>
JavaScript 小刮号
查看>>
BZOJ USACO 银组 水题集锦
查看>>
Android为TV端助力 Linux命令查看包名类名
查看>>
【zabbix】自动注册,实现自动发现agent并添加监控(agent不需要任何配置)
查看>>
[简单到爆]eclipse-jee-neon的下载和安装
查看>>
vector
查看>>
Redis学习之set类型总结
查看>>
栈和队列
查看>>
CSS2-3常见的demo列子总结一
查看>>
XML & JSON---iOS-Apple苹果官方文档翻译
查看>>
数据挖掘之功能
查看>>
2018-07-13E-R图设计数据库+三大范式+修改用户密码+分配用户权限
查看>>
移动广告行业的复苏
查看>>
Cookie机制,session机制
查看>>
nginx配置错误
查看>>
47 【golang】mysql操作
查看>>
Using ARITHABORT with LLBLGen
查看>>
增量模型与快速模型的异同。
查看>>
Hanoi双塔问题(简单的枚举)
查看>>