博客
关于我
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/

你可能感兴趣的文章
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No static resource favicon.ico.
查看>>
no such file or directory AndroidManifest.xml
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
no1
查看>>