美文网首页
vuex 写法注意事项

vuex 写法注意事项

作者: 空气KQ | 来源:发表于2019-08-27 16:53 被阅读0次

computed

import { mapGetters } from 'vuex'
 computed: mapState(['count']),//// 映射 this.count 为 store.state.count
computed: {
  localComputed () { /* ... */ },
  // 使用对象展开运算符将此对象混入到外部对象中
  ...mapState({
    // ...
  })
}
mapGetters({
  // 把 `this.doneCount` 映射为 `this.$store.getters.doneTodosCount`
  doneCount: 'doneTodosCount'
})

import { mapMutations } from 'vuex'

import { mapMutations } from 'vuex'

export default {
  // ...
  methods: {
    ...mapMutations([
      'increment', // 将 `this.increment()` 映射为 `this.$store.commit('increment')`

      // `mapMutations` 也支持载荷:
      'incrementBy' // 将 `this.incrementBy(amount)` 映射为 `this.$store.commit('incrementBy', amount)`
    ]),
    ...mapMutations({
      add: 'increment' // 将 `this.add()` 映射为 `this.$store.commit('increment')`
    })
  }
}
import { mapActions } from 'vuex'

export default {
  // ...
  methods: {
    ...mapActions([
      'increment', // 将 `this.increment()` 映射为 `this.$store.dispatch('increment')`

      // `mapActions` 也支持载荷:
      'incrementBy' // 将 `this.incrementBy(amount)` 映射为 `this.$store.dispatch('incrementBy', amount)`
    ]),
    ...mapActions({
      add: 'increment' // 将 `this.add()` 映射为 `this.$store.dispatch('increment')`
    })
  }
}

相关文章

  • vuex 写法注意事项

    computed import { mapMutations } from 'vuex'

  • 历史记录

    单个组件中写法 引入 vuex写法

  • vuex-class用法

    vuex-class可以包装vuex的写法,使代码简化 Installation $ npm install --...

  • vuex与axios的优化写法

    vuex与axios的优化写法 封装方法 使用方法 vuex: action.js get post put de...

  • vuex 简洁写法

    在src下新建一个 /store/index.js,内容如下 在main.js里面引用 这样就可以在vue里面使用了:

  • 手写简单Vuex

    手写 vuex 插件固定写法 混入 创建 Store 由于需要使用 new Vuex.Store 来创建,所以 V...

  • vuex

    VUEX and router 简化vuex的写法,从而提高开发效率:1.简化state第一步:引入import ...

  • VUEX 入门(组件写法)

    1. 简述 VUEX网上有不少教程,我也看了官方和不少博客的教程,但是还是看的不爽,因为总是用全局的写法,而实际...

  • ES2015 箭头函数

    箭头函数用法 传统写法: 箭头函数写法: 注意,在只有一个参数和一条执行语句时,可以简化为下面的写法: 注意事项 ...

  • vuex基础用法

    简单汇总一下vuex的最基础的用法 服务端渲染的写法(推荐使用)

网友评论

      本文标题:vuex 写法注意事项

      本文链接:https://www.haomeiwen.com/subject/aoneectx.html