Home > Web Front-end > JS Tutorial > body text

vuex export object pair adds value to state

php中世界最好的语言
Release: 2018-06-14 11:48:40
Original
1834 people have browsed it

This time I will bring you the vuex export object to add value to the state. What are the precautions for the vuex export object to add the value to the state. The following is a practical case, let's take a look.

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)
Copy after login

Get the value of useredit from state

this.$store.state.useredit
Copy after login

2 Add the value to the state in the object pair exported by vuex

Add mutations to change the state Value

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)
Copy after login

In main.js

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

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related matters on the php Chinese website article!

Recommended reading:

How to use Angular component interaction

##Use vue-route beforeEach to make navigation guards

The above is the detailed content of vuex export object pair adds value to state. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!