您好,欢迎访问一九零五行业门户网

vuex使用步骤详解

这次给大家带来vuex使用步骤详解,vuex使用的注意事项有哪些,下面就是实战案例,一起来看一下。
vuex是一个专门为vue.js设计的集中式状态管理架构。状态?我把它理解为在data中的属性需要共享给其他vue组件使用的部分,就叫做状态。简单的说就是data中需要共用的属性。
1.在vue 组件中
执行enabledcheckbox方法 ,true 为参数,用来改变state中的值
this.$store.dispatch(enabledcheckbox,true)
从state获取useredit的值
this.$store.state.useredit
2 在vuex导出的对象对添加 值到state
添加 mutations 来改变state的值
添加 actions 来 mutations
import vue from 'vue' import vuex from 'vuex' vue.use(vuex) export default new vuex.store({     state: {       useredit: false,     },     mutations: {       enabledcheckbox(state, value) {         state.checkboxdisable = value       },     },     actions: {       enabledcheckbox({ commit }, value) {         commit('enabledcheckbox', value)       },     }   })   //console.log(vuex)
在main.js
import store from './vuex' new vue({  el: '#app',  router,  store,  render:h=>h(app) })
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
vue+axios实现数据交互
angular component实用技巧详解
以上就是vuex使用步骤详解的详细内容。
其它类似信息

推荐信息