博客
关于我
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报错:the “ssl“ parameter requires ngx_http_ssl_module in usrlocalnginxconfnginx.conf128
查看>>
nginx日志分割并定期删除
查看>>
Nginx日志分析系统---ElasticStack(ELK)工作笔记001
查看>>
Nginx映射本地json文件,配置解决浏览器跨域问题,提供前端get请求模拟数据
查看>>
Nginx映射本地静态资源时,浏览器提示跨域问题解决
查看>>
nginx最最最详细教程来了
查看>>
Nginx服务器---正向代理
查看>>
Nginx服务器上安装SSL证书
查看>>
Nginx服务器基本配置
查看>>
Nginx服务器的安装
查看>>
Nginx标准配置文件(包括反向代理、大文件上传、Https证书配置、文件预览等)
查看>>
Nginx模块 ngx_http_limit_conn_module 限制连接数
查看>>
Nginx模块 ngx_http_limit_req_module 限制请求速率
查看>>
nginx添加允许跨域header头
查看>>
nginx添加模块与https支持
查看>>
nginx状态监控
查看>>
Nginx用户认证
查看>>
Nginx的location匹配规则的关键问题详解
查看>>
Nginx的Rewrite正则表达式,匹配非某单词
查看>>
Nginx的使用总结(一)
查看>>