博客
关于我
VUE2 入坑指南07--vuex
阅读量:180 次
发布时间:2019-02-28

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

vuex是什么

  • Vuex 是一个专为vue.js应用程序开发的状态管理模式;
  • 说人话:公有数据放于公共区域,做数据共享,以便各个组件之前调用

vuex使用

  1. npm i vuex -S
  2. 在一个模块化的打包系统中,必须显式的通过 Vue.use() 来安装 Vuex;
    main.js:
import Vue from 'vue'import Vuex from 'vuex'Vue.use(Vuex) //注册vuex到vue中var store = new Vuex.Store({   	state: {    //类似于组件中的 data ,专门用来存储数据的		count: 0  //组建中访问输出 this.$store.state.*** 来访问	},	mutations: {   		//注意:如果要操作store中的state值,只能调用mutations提供的方法,不推荐在组建中直接操作state中的数据,万一导致了数据紊乱,不能快速定位到错误源		increment(state){   			state.count++		}		//注意:如果组件要调用mutations中的方法,只能使用this.$store.commit('方法名')	}})import App from './App.vue'const vm = new Vue({   	el:'#app',	render: c => c(App),	router: router,	store: store //挂载到vue实例上})

转载地址:http://otui.baihongyu.com/

你可能感兴趣的文章
nginx安装并配置实现端口转发
查看>>
nginx安装配置
查看>>
Nginx实战之1.1-1.6 Nginx介绍,安装及配置文件详解
查看>>
Nginx实战经验分享:从小白到专家的成长历程!
查看>>
nginx实现二级域名转发
查看>>
Nginx实现动静分离
查看>>
Nginx实现反向代理负载均衡
查看>>
nginx实现负载均衡
查看>>
Nginx将https重定向为http进行访问的配置(附Demo)
查看>>
nginx工作笔记004---配置https_ssl证书_视频服务器接口等
查看>>
nginx工作笔记005---nginx配置负载均衡_在微服务中实现网关集群_实现TCP传输层协议__http协议的负载均衡
查看>>
nginx常用命令及简单配置
查看>>
Nginx常用屏蔽规则,让网站更安全
查看>>
nginx开机启动脚本
查看>>
nginx异常:the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf
查看>>
nginx总结及使用Docker创建nginx教程
查看>>
nginx报错:the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:128
查看>>
nginx报错:the “ssl“ parameter requires ngx_http_ssl_module in usrlocalnginxconfnginx.conf128
查看>>
nginx日志分割并定期删除
查看>>
Nginx日志分析系统---ElasticStack(ELK)工作笔记001
查看>>