[关闭]
@2890594972 2017-10-26T00:47:28.000000Z 字数 614 阅读 820

vue重点强化--使用vuex

vue


第一:调用mutations:

  1. this.$store.commit('changeKeyword',this.iptValue);

第二:mutations修改state

  1. mutations:{
  2. changeKeyword(state,newkeyword){
  3. state.keyword = newkeyword;
  4. }
  5. }

第三:state如何定义

  1. state: {
  2. title:'1506',
  3. keyword:''
  4. }

第四:js组件化

  1. export default new Vuex.Store({})

最后:综上所述

  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex)
  4. //暴露对象接口
  5. export default new Vuex.Store({
  6. state: {
  7. title: '1506',
  8. keyword: ''
  9. },
  10. mutations: {
  11. autoIncrement(state, param) {
  12. +state.title++
  13. },
  14. changeKeyword(state, newkeyword) {
  15. state.keyword = newkeyword;
  16. }
  17. },
  18. actions: {
  19. //triggerMe如何触发
  20. triggerMe(actions, v) {
  21. }
  22. }
  23. })

实力化组件

  1. new Vue({
  2. el: '#app',
  3. router,
  4. store,
  5. template: '<App/>',
  6. components: { App }
  7. })
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注