• <noscript id="ggggg"><dd id="ggggg"></dd></noscript>
    <small id="ggggg"></small> <sup id="ggggg"></sup>
    <noscript id="ggggg"><dd id="ggggg"></dd></noscript>
    <tfoot id="ggggg"></tfoot>
  • <nav id="ggggg"><cite id="ggggg"></cite></nav>
    <nav id="ggggg"></nav>
    成人黃色A片免费看三更小说,精品人妻av区波多野结衣,亚洲第一极品精品无码,欧美综合区自拍亚洲综合,久久99青青精品免费观看,中文字幕在线中字日韩 ,亚洲国产精品18久久久久久,黄色在线免费观看

    關于Vuex的全家桶狀態管理(二)

    2018-5-28    seo達人

    如果您想訂閱本博客內容,每天自動發到您的郵箱中, 請點這里

    1:mutations觸發狀態 (同步狀態)

    <template> <p class="hello"> <h1>Hello Vuex</h1> <h5>{{count}}</h5> <p> <button @click="jia">+</button> <button @click="jian">-</button> </p> </p> </template> <script> import {mapState,mapMutations} from 'vuex' export default{
      name:'hello', //寫上name的作用是,如果你頁面報錯了,他會提示你是那個頁面報的錯,很實用 //方法三 computed: mapState([ 'count' ]),
      methods:{
       ...mapMutations([ 'jia', 'jian' ])
      }
     } </script>
        
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    2:getters計算屬性

    getter不能使用箭頭函數,會改變this的指向

    在store.js添加getters

     // 計算 const getters = {
      count(state){ return state.count + 66 }
    } export default new Vuex.Store({
      state,
      mutations,
      getters
    })
        
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    //count的參數就是上面定義的state對象 
    //getters中定義的方法名稱和組件中使用的時候一定是一致的,定義的是count方法,使用的時候也用count,保持一致。 
    組件中使用

    <script> import {mapState,mapMutations,mapGetters} from 'vuex' export default{
      name:'hello',
      computed: {
       ...mapState([ 'count' ]),
       ...mapGetters([ 'count' ])
      },
      methods:{
       ...mapMutations([ 'jia', 'jian' ])
      }
     } </script>
        
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    3:actions (異步狀態)

    在store.js添加actions

    import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) // 定義常量 const state = { count: 1 } // mutations用來改變store狀態 同步狀態 const mutations = {
      jia(state){
        state.count ++
      },
      jian(state){
        state.count --
      },
    } // 計算屬性 const getters = {
      count(state){ return state.count + 66 }
    } // 異步狀態 const actions = {
      jiaplus(context){
        context.commit('jia') //調用mutations下面的方法
        setTimeout(()=>{
          context.commit('jian')
        },2000) alert('我先被執行了,然后兩秒后調用jian的方法') }, jianplus(context){ context.commit('jian') }
    } export default new Vuex.Store({
      state,
      mutations,
      getters,
      actions
    })
        
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44

    在組件中使用

    <template> <p class="hello"> <h1>Hello Vuex</h1> <h5>{{count}}</h5> <p> <button @click="jia">+</button> <button @click="jian">-</button> </p> <p> <button @click="jiaplus">+plus</button> <button @click="jianplus">-plus</button> </p> </p> </template> <script> import {mapState,mapMutations,mapGetters,mapActions} from 'vuex' export default{
      name:'hello',
      computed: {
       ...mapState([ 'count' ]),
       ...mapGetters([ 'count' ])
      },
      methods:{ // 這里是數組的方式觸發方法 ...mapMutations([ 'jia', 'jian' ]), // 換一中方式觸發方法 用對象的方式 ...mapActions({
        jiaplus: 'jiaplus',
        jianplus: 'jianplus' })
      }
     } </script> <style scoped> h5{ font-size: 20px; color: red; } </style>
        
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48

    4:modules 模塊

    適用于非常大的項目,且狀態很多的情況下使用,便于管理

    修改store.js

    import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) const state = { count: 1 } const mutations = {
      jia(state){
        state.count ++
      },
      jian(state){
        state.count --
      },
    } const getters = {
      count(state){ return state.count + 66 }
    } const actions = {
      jiaplus(context){
        context.commit('jia') //調用mutations下面的方法
        setTimeout(()=>{
          context.commit('jian')
        },2000) alert('我先被執行了,然后兩秒后調用jian的方法') }, jianplus(context){ context.commit('jian') }
    }
    
    //module使用模塊組的方式 moduleA const moduleA = { state, mutations, getters, actions }
    
    // 模塊B moduleB const moduleB = { state: { count:108
      }
    } export default new Vuex.Store({
      modules: {
        a: moduleA,
        b: moduleB,
      }
    })
    藍藍設計www.lzhte.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 平面設計服務

    日歷

    鏈接

    個人資料

    藍藍設計的小編 http://www.lzhte.cn

    存檔

    主站蜘蛛池模板: 伊人视屏| 国产男人午夜视频在线观看 | 精品国产成人av在线| 国产激情国语对白普通话| 一夜七次郎最新网站| 久久亚洲国产精品成人av秋霞| 国产午夜福利在线机视频| 久久精品国产久精国产爱| 久久er国产精品免费观看1| 久久久无码精品午夜| aⅴ亚洲 日韩 色 图网站 播放 | 国产在线观看成人91| 亚洲综合精品中文字幕| 精品日韩av在线播放| 人妻久久久精品99系列2021| 性欧美vr高清极品| 成本人片无码中文字幕免费| 激情丝袜欧美专区在线观看| 中文字幕AV日韩精品一区二区| 天堂网www在线资源网| 久久18禁高潮出水呻吟娇喘| 金门县| 治县。| 最新精品国偷自产在线| 97久久超碰国产精品| 成人亚欧欧美激情在线观看| 国产午夜福利视频合集| 亚洲人成网线在线播放VA| 亚洲成a人片在线网站| 亚欧免费无码aⅴ在线观看| 国产精品视频第一区二区三区| 免费观看男女性高视频| 午夜福利在线观看6080| 国内精品一区二区三区东京| 国产成人精品午夜视频'| 国产精品女人呻吟在线观看| 风流少妇一区二区三区| 日本岛国大片不卡人妻| 国产永久免费高清在线观看视频| 日韩av影院在线观看| 99九九99九九视频精品|