zoukankan      html  css  js  c++  java
  • <vuex第二弹>vuex之Getter(前端网备份)

    所有的结构都参考上一弹
    Vuex 允许我们在 store 中定义“getter”(可以认为是 store 的计算属性)。
    index.js
    //vue 2.0官方建议在computed里面的不使用箭头函数,因为箭头函数的this 指向上一层,而function的this指向本层
    const getters={
    count:function(state){
    return state.count+=100
    }
    }
    export default new Vuex.Store({
    state,
    mutations,
    getters
    })
    vue
    import { mapState,mapMutations,mapGetters } from 'vuex'
    然后主要是写法的区别
    这里主要有2种写法的区别,未注释的是用了mapGetters的简写,注意vue的cpmputed的结构以及以后在这里的map之前都得加...
    computed:{
    ...mapState([
    'count'
    ]),
    ...mapGetters([
    'count'
    ])
    // count(){
    // return this.$store.getters.count;
    // }
    },

  • 相关阅读:
    一些基础的前端技术面试问题
    HTTP与HTTPS区别
    XML与JSON
    js的内置对象
    二分法查找
    img下面的留白解决
    大家好
    HEOI2020游记
    CSP-S2019游记
    省选模拟八十六 题解
  • 原文地址:https://www.cnblogs.com/lsc-boke/p/10997239.html
Copyright © 2011-2022 走看看