Vuex用法汇总

获取

方法一

<template>
  <view class="page">状态:{{getStatus}}</view>
</template>
<script>
import {mapState} from 'vuex';
export default {
    computed: {
        ...mapState(['getStatus'])
    }
}
</script>

方法二

<script>
import {mapGetters} from 'vuex';
export default {
    computed: {
        ...mapGetters({status: 'getStatus'})
    },
    onShow() {
        console.log(this.status)
    }
}
</script>

方法二

<script>
export default {
    onShow() {
        // console.log(this.$store.getters.getStatus)
    }
}
</script>

变更

<script>
export default {
    onShow() {
        this.$store.commit('setStatus', 1) //同步
        this.$store.dispatch('setStatus', 1) //异步
    }
}
</script>

 140 total views,  8 views today

Revisions

Comments are closed.