Home  >  Article  >  Web Front-end  >  Simple use of vuex

Simple use of vuex

亚连
亚连Original
2018-05-26 16:36:311426browse

vuex is a centralized state management architecture specially designed for vue.js. This article mainly introduces the simple use of vuex. Friends who need it can refer to

What is Vuex?

vuex is a centralized state management architecture specially designed for vue.js. state? I understand it as the part where the attributes in data need to be shared with other vue components, which is called state. Simply put, it is the attributes that need to be shared in data.

1. In the vue component

execute the enabledcheckbox method, true is the parameter, used to change the value in state

  this.$store.dispatch("enabledcheckbox",true)

Get the value of useredit from state

this.$store.state.useredit

2 Exported in vuex Objects add values ​​to state

Add mutations to change the value of state

Add actions to 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)

In main.js

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

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to upload files using jQuery Ajax

Use ajax to implement asynchronous refresh requests

Upload files through Ajax and use FormData to make Ajax requests

The above is the detailed content of Simple use of vuex. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn