vuex安装

1.先新建一个文件夹lesson,打开vscode中lesson文件夹,新建一个demo01文件夹,再建一个index.html

2.在index.html中引入vue和vuex

vuex官网

 

 vue官网

 

 

 

 以我为例 在index.html

 

3.引入 Vuex 之后,让我们来创建一个 store。创建过程直截了当——仅需要提供一个初始 state 对象和一些 mutation:

<html>
    <head>
        <title>vuex安装</title>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <script src="https://unpkg.com/vuex@3.6.2/dist/vuex.js"></script>
    </head>
    <body>
        <script>
            const store = new Vuex.Store({
                    state: {
                        count: 0
                    },
                    mutations: {
                        increment(state) {
                            state.count++
                        }
                    }
                })
                console.log("store->", store.state.count);
                store.commit('increment')
                console.log("store2->", store.state.count);

        </script>
    </body>
</html>

index.html 打开网页 按F12 检查控制台console

 

 

 

 

显示1即可

posted @ 2021-02-08 22:19  Hhhr  阅读(83)  评论(0编辑  收藏  举报