1、安装构建vue-router
npm i vue-router@next
2、创建router/index.js文件
import { createRouter, createWebHashHistory } from 'vue-router'
import Home from '@/views/home.vue'
const Router = createRouter({
history: createWebHashHistory(),
routes: [{
path: '/',
name: 'home',
component: Home
}]
})
export default Router
3、安装构建vuex
npm i vuex@next
4、创建store/index.js文件
import { createStore } from 'vuex'
const store = createStore({
state: {
},
getters: {
},
mutations: {
},
actions: {
},
modules: {
}
})
export default store
5、在main.js中使用router和store
import { createApp } from 'vue'
import App from './App.vue'
import router from './router/index.js'
import store from './store/index.js'
createApp(App).use(router).use(store).mount('#app')