“Live up to the time, the creation of non-stop, this article is participating in 2021 year-end summary essay competition”
- Go to the directory where you want to create the project and use NPM: Execute
npm init vite@latest
Type the name of the project you want to create, then press Enter
- Frame selection
- Select js or TS for your project and press Enter
The initialized project directory is as follows
- Create required directories and install required dependencies
1) Install and configure the Router
npm install vue-router@4
Copy the code
Then create the corresponding directory under SRC
Next, create the index.js file in the Router folder
import { createRouter, createWebHashHistory } from "vue-router"; import Star from ".. /views/star/index.vue"; const routes = [ { path: "/", redirect: "/star", }, { path: "/star", name: "Star", component: Star, }, ]; const router = createRouter({ history: createWebHashHistory(), routes, }); export default router;Copy the code
Modify the main.js file
import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
createApp(App).use(router).mount("#app");
Copy the code
Create a page file corresponding to the route in the views directory
Modify the app.vue file
<template>
<router-view />
</template>
Copy the code
(To be continued…)