• <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久久久久久,黄色在线免费观看

    關(guān)于Vuex的全家桶狀態(tài)管理(二)

    2018-5-28    seo達(dá)人

    如果您想訂閱本博客內(nèi)容,每天自動(dòng)發(fā)到您的郵箱中, 請點(diǎn)這里

    1:mutations觸發(fā)狀態(tài) (同步狀態(tài))

    <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的作用是,如果你頁面報(bào)錯(cuò)了,他會(huì)提示你是那個(gè)頁面報(bào)的錯(cuò),很實(shí)用 //方法三 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計(jì)算屬性

    getter不能使用箭頭函數(shù),會(huì)改變this的指向

    在store.js添加getters

     // 計(jì)算 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的參數(shù)就是上面定義的state對象 
    //getters中定義的方法名稱和組件中使用的時(shí)候一定是一致的,定義的是count方法,使用的時(shí)候也用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 (異步狀態(tài))

    在store.js添加actions

    import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) // 定義常量 const state = { count: 1 } // mutations用來改變store狀態(tài) 同步狀態(tài) const mutations = {
      jia(state){
        state.count ++
      },
      jian(state){
        state.count --
      },
    } // 計(jì)算屬性 const getters = {
      count(state){ return state.count + 66 }
    } // 異步狀態(tài) const actions = {
      jiaplus(context){
        context.commit('jia') //調(diào)用mutations下面的方法
        setTimeout(()=>{
          context.commit('jian')
        },2000) alert('我先被執(zhí)行了,然后兩秒后調(diào)用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:{ // 這里是數(shù)組的方式觸發(fā)方法 ...mapMutations([ 'jia', 'jian' ]), // 換一中方式觸發(fā)方法 用對象的方式 ...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 模塊

    適用于非常大的項(xiàng)目,且狀態(tài)很多的情況下使用,便于管理

    修改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') //調(diào)用mutations下面的方法
        setTimeout(()=>{
          context.commit('jian')
        },2000) alert('我先被執(zhí)行了,然后兩秒后調(diào)用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,
      }
    })
    藍(lán)藍(lán)設(shè)計(jì)www.lzhte.cn )是一家專注而深入的界面設(shè)計(jì)公司,為期望卓越的國內(nèi)外企業(yè)提供卓越的UI界面設(shè)計(jì)、BS界面設(shè)計(jì) 、 cs界面設(shè)計(jì) 、 ipad界面設(shè)計(jì) 、 包裝設(shè)計(jì) 、 圖標(biāo)定制 、 用戶體驗(yàn) 、交互設(shè)計(jì)、 網(wǎng)站建設(shè) 平面設(shè)計(jì)服務(wù)

    日歷

    鏈接

    個(gè)人資料

    存檔

    主站蜘蛛池模板: 国产免费午夜精品理论 | 性欧美老人牲交XXXXX视频| 日本中文一二区有码在线| 久久人妻中文字幕免费| 久久久久成人精品无码中文字幕| 亚洲蜜臀av乱码久久| 一区二区高清国产视频| 无码四区| 夜色资源站国产www在线视频| a一级特黄日本大片 s色| 日本啪啪一区二区三区| 久久88香港三级台湾三级播放| 日韩人妻精品无码一区二区三区| 日韩欧美综合在线二区三区| 国产微拍精品一区二区三区 | 崇仁县| 国产成人自拍小视频在线| 亚洲国产成人久久综合电影| 亚洲AV婷婷五月产AV中文| A级毛片高清免费视频就| 都安| 好深好爽办公室做视频| 91精品少妇高潮一区二区三区不卡| 日韩亚洲AV最新在线观看| 激情五月亚洲中文字幕| 免费在线观看污视频| 望谟县| 欧美一区二区三区男人的天堂| 四虎国产精品亚洲一区久久特色| 亚洲精品一二三四区| 色综合久久久久8天国| 久久精品全国免费观看国产| 久艹在线| 日本一区二区三区午夜| 最新永久免费AV无码网站| 亚洲午夜无码毛片av久久京东热| 日韩精品无码免费专区网站| 成人H动漫精品一区二区无码| 国产成人a在线观看视频| 伊人精品无码一区二区三区电影| 国产毛片片精品天天看视频|