uni-app使用vuex

        //1.根目录创建store文件->index.js
        import Vue from ‘vue’
        import Vuex from ‘vuex’

        Vue.use(Vuex)

        const store = new Vuex store ({
            state: {
                name: ‘’
            },
            getters: {
                
            },
            mutations: {
    
            },
            actions: {

            }
        })
        
        export default store

    //2.main.js下引入和挂载
        import store from ‘./store’
        Vue.prototype.$store = store
        const app = new Vue ({
            store
        })

       //3.页面引用
        <template>
            <div>
                {{name}}
            </div>
        </template>
        <scipt>
            import {mapState} from ‘vuex’
            export default {
                onLoad() {
                    console.log(this.$store)
                },
                computed: {
                    …mapState([‘name’])
                }
            }
        </script>
                

 

uni-app使用vuex

上一篇:H3 BPM微信接入配置


下一篇:LBDP-Z APP在线升级指南