Home  >  Article  >  Web Front-end  >  Implement the initialization method of vuex

Implement the initialization method of vuex

巴扎黑
巴扎黑Original
2017-07-21 17:07:262349browse

Create store folder

1. Function: put asynchronous operations

File: actions.js

Content:

2. Function: Get data in state

File: getters.js

Content:

export const singer = state => state.singer

3. Function: Place method name

File: mutation-types.js

Content:

export const SET_SINGER = 'SET_SINGER'

4. Function: Manipulate state data

File: mutations.js

Content:

import * as types from './ mutation-types'

const mutation = {

[types.SET_SINGER](state,singer){

state.singer = singer

}

}

export default mutations

5. Function: Data

File: state.js

Content :

const state = {

singer:{}

}

export default state

6 .Function: Entry

File: index.js

Content:

import Vue from 'vue'

import Vuex from 'vuex'

import * as actions from './actions'

import * as getter from './getters'

import mutations from './mutations'

import state from './state'

import createLogger from 'vuex/dist/logger'

Vue.use(Vuex)

// When developing the environment, track each time Modification of state

const debug = process.env.NODE_ENV !== 'production'

export default new Vuex.Store({

actions,

getters,

mutations,

state,

strict: debug,

plugin: debug ? [createLogger()] : []

})

The above is the detailed content of Implement the initialization method 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