首页 > 移动平台 > 详细

uni-app使用vuex

时间:2020-03-30 11:14:33      阅读:197      评论:0      收藏:0      [点我收藏+]
        //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

原文:https://www.cnblogs.com/wei-dong/p/12597244.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!