webpack搭建vue3教程-超级篇
一.配置vue-router:
1.安装依赖:
npm install vue-router@4 -S
2.配置router:
src/router/index.js
import { createRouter, createWebHistory } from "vue-router";
import Home from ‘./Home.vue‘;
import Me from ‘./Me.vue‘;
const routerHistory = createWebHistory();
const router = createRouter({
history: routerHistory,
routes: [
{
path: ‘/home‘,
name: ‘Home‘,
component: Home
},
{
path: ‘/me‘,
name: ‘Me‘,
component: Me
}
]
});
export default router;
3.使用router:
在index.js导入router:
import router from ‘./router.js‘;
createApp(App).use(router).mount(‘#app‘)
二.配置vuex:
1.安装依赖:
npm install vuex@next -S
2.配置:
src/store/index.js
import { createStore } from "vuex";
const store = createStore({
state: {
name: ‘vuex‘
},
getters: {},
actions: {},
mutations: {},
modules: {}
});
export default store;
3.使用:
import store from "./store/index.js";
createApp(App).use(router).use(store).mount(‘#app‘)