安装 vuex4和vue-router4
npm install vuex@next vue-router@next -S
使用
创建文件src/router/index.js
创建文件 src/store/index.js
import { createRouter, createWebHistory } from 'vue-router'
import { createStore } from 'vuex'
// new 转换成工厂函数
const router = createRouter({
history: createWebHistory(),
routes: [
{ path: '/', component: () => import('views/home.vue') },
{ path: '/about', component: () => import('views/about.vue') }
]
})
export default router
main.js中导入,使用
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
createApp(App)
.use(router)
.use(store)
.mount('#app')