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

Implement the initialization method of vuex

巴扎黑
Release: 2017-07-21 17:07:26
Original
2415 people have browsed it

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!

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