vue3安装vuex

vue3安装vuex

安装

# npm
npm install vuex@next --save

# yarn
yarn add vuex@next --save

新建 store 文件夹

路径:/src/store

新建 index.ts 文件

路径:/src/store/index.ts

import { isString } from "@vue/shared";
import { createStore } from "vuex";

export default createStore({
  state: {
    count: 0
  },
  getters: {},
  mutations: {
    increment(state, value: number): void {

      state.count = value;
    }
  },
  actions: {},
  modules: {},
});

main.ts

import { createApp } from 'vue';
import App from './App.vue';
import store from "./store";

const app = createApp(App);

app.use(store).mount('#app');

setup 中访问路由和当前路由




你可能感兴趣的:(vue3,vue.js,javascript,前端)