蜜桃精品成人影片,99国产精品偷窥熟女精品视频,啊灬啊灬啊灬快灬A片免费,b站大全永不收费免费下载软件吗,重囗味sM在线观看无码

Vuex中map方法的使用

時間:2024-04-19 10:50:02 類型:vue
字號:    

1, mapState方法: 用于幫助我們映射state中的數據為計算屬性\

import {mapState,mapGetters} from 'vuex'

 computed:{
        //借助mapState生成計算屬性, 從state中讀取數據(對象寫法)
        // ...mapState({sum:'sum',school:'school',subject:'subject'}),
        //借助mapState生成計算屬性, 從state中讀取數據(數組寫法)
        ...mapState(['sum','school','subject']),
        
        //以上相當于下面的寫法
        // sum(){
        //     return this.$store.state.sum
        // },
        // school(){
        //     return this.$store.state.school
        // },
        // subject(){
        //     return this.$store.state.subject
        // }
    },

2, mapGetters方法: 用于幫助我們映射getters中的數據為計算屬性

computed:{
        //借助mapGetters生成計算屬性, 從getters中讀取數據(對象寫法)
        // ...mapGetters({bigSum:'bigSum'})
        //借助mapGetters生成計算屬性, 從getters中讀取數據(數組寫法)
         ...mapGetters(['bigSum'])
          //以上相當于下面的寫法
        //   ,bigSum(){
        //         return this.$store.getters.bigSum
        //   }
    },

3, mapActions方法:用于幫助我們生成與actions對話的方法, 即:包含$store.dispatch(xxx)的函數

methods:{
        //程序員自己寫
        // increment(){
        //     this.$store.dispatch('increment',this.n)
        //     //dispatch中的increment: 對應store.js中actions中的increment方法

        // },

        //借助mapActions生成對應的方法,方法中會調用dispatch去聯(lián)系actions(對象寫法)
        // ...mapActions({'increment':'increment'})

        //借助mapActions生成對應的方法,方法中會調用dispatch去聯(lián)系actions(數組寫法)
        ...mapActions(['increment'])
    }

4, mapMutations方法: 用于幫助我們生成與muattions對話的方法, 即: 包含 $store.commit(xxx)的函數

methods:{
        //程序員自己寫
        // deincrement(){
        //     this.$store.commit('DEINCREMENT',this.n)
        //     //commit中的increment: 對應store.js中mutations中的increment方法
        //     //如果不需要actions做什么(即不需要服務員做什么), 可以直接找后廚

        // },
        //借助mapMutations生成對應的方法,方法中會調用commit去聯(lián)系mutations(對象寫法)
        // ...mapMutations({'DEINCREMENT':'DEINCREMENT'})
        //借助mapMutations生成對應的方法,方法中會調用commit去聯(lián)系mutations(數組寫法)
        ...mapMutations(['DEINCREMENT']),
        //注意,以上調用方法要傳值
    }


<