mutations.js file calls this method of writing file writing specifications and templates

1) mutations.js code is as follows

const mutations={
    add(state){
        state.count++
    },
    reduce(state){
        state.count--
    }
}

 2) In the button, a direct call by a commit.

<button @click="$store.commit('add')">+</button>
<button @click="$store.commit('reduce')">-</button>

 In the case of code in assembly home.vue

<Template> 
  <div class = "Home"> 
    <Button @click = "$ store.commit ( 'the Add')"> + </ Button> 
    <Button @click = "$ store.commit ( 'the reduce')"> - </ Button> 

    <P> reference state option a variable: {{COUNT}} </ P> 
    </ div> 
</ Template> 
<Script> 
Export default { 
  name: 'Home', 
  Data () { 
    return { 
      MSG : 'Home.vue components' 
    } 
  }, 
  computed: { 
    // call is vuex, state options file rootState.js declare variables 
    COUNT () { 
      console.log ( 'the this structure:' + this $ store.state.count. ) 
      return the this. $ store.state.count
    }
  }
}
</script>

 

Guess you like

Origin www.cnblogs.com/asplover/p/11355279.html