目录
安装router
- 在vscode中来到你的项目文件夹中
- 在终端中执行命令安装router:npm i vue-router -D
- 等待下载安装
- 安装好以后,在项目目录的src目录内,新建目录 modules 用于存放插件模块
- 在moudules内新建路由配置文件 route.js
- 里面写如下内容:
import { createRouter, createWebHistory } from "vue-router"
const router = createRouter({
routes: [],
history: createWebHistory()
})
export default router
修改main.js
- 导入router : import router from "./modules/router"
- 使用router : app.use(router)
- 最终main.js文件内容:
import { createApp } from 'vue'
import App from './App.vue'
import router from "./modules/router"
const app = createApp(App)
app.use(router)
app.mount('#app')
创建pages
- 在src目录下,新建文件夹pages,用于存放页面
- 在里面新建2个示例页面:hello.vue,home.vue
- hello.vue
- -
- home.vue
- 在App.vue中使用路由,修改App.vue:
<template>
<router-view></router-view>
</template>
在router.js中配置页面
- 上面两个页面(hello.vue和home.vue)新建后路由是不知道的,我们需要在配置文件router.js中告诉它,因此需要修改router.js
- 在routes数组中增加对应页面的配置:
{
name:"主页",
component: () => import('../pages/home.vue')
},
{
name:"欢迎",
path:"/hello",
component: () => import('../pages/hello.vue')
}
- -
- name:页面名称,随意
- path:在浏览器访问的时候的路径
- component:导入访问的页面文件
- 由于第一个就是默认的主页,所以不需要写path
- 访问第二个的浏览器路径就是:http://localhost:3000/hello
- router.js总体代码:
import { createRouter, createWebHistory } from "vue-router"
const router = createRouter({
routes: [
{
name:"主页",
component: () => import('../pages/home.vue')
},
{
name:"欢迎",
path:"/hello",
component: () => import('../pages/hello.vue')
}
],
history: createWebHistory()
})
export default router
- 到这里基本就配置完成了,运行项目看看:npm run dev
- 主页:
- 欢迎页:
配置文件路由
当我们增加页面时,总要在router中配置一下,一旦页面多起来就很麻烦,所以可以安装文件路由,也就是以文件夹pages内的文件结构自动作为访问路径。
- 安装文件路由插件
- npm i -D vite-plugin-pages
- 在vite.config.js中增加配置:
import Pages from "vite-plugin-pages"
export default defineConfig({
plugins:[
//...
Pages(),
]
})
- 修改后的vite.config.js :
- 修改router.js
- 从pages文件夹中导入
- 去掉routes内容
import { createRouter, createWebHistory } from "vue-router"
import routes from "~pages";
const router = createRouter({
routes,
history: createWebHistory()
})
export default router
- 到这里就完成了,但要注意的是,页面里主页不是home.vue了,默认的是index.vue,由于我们示例中并没有这个文件,因此访问http://localhost:3000就会报警告。而访问原来的home.vue就需要改为http://localhost:3000/home
mexican pharmacy mexico drug stores pharmacies mexico pharmacies prescription drugs
acyclovir over the counter canada
mexican pharmaceuticals online: buying prescription drugs in mexico online – mexican online pharmacies prescription drugs
pharmacies in mexico that ship to usa: medicine in mexico pharmacies – п»їbest mexican online pharmacies
https://mexicandeliverypharma.online/# pharmacies in mexico that ship to usa
смотреть порно коллекции смотреть порно коллекции .
https://mexicandeliverypharma.online/# buying prescription drugs in mexico online
mexico drug stores pharmacies mexican mail order pharmacies buying from online mexican pharmacy
lyrica cap
buying prescription drugs in mexico: mexican mail order pharmacies – mexico drug stores pharmacies
best online pharmacies in mexico: mexican drugstore online – mexican pharmaceuticals online
п»їbest mexican online pharmacies: buying prescription drugs in mexico – buying prescription drugs in mexico
best online pharmacies in mexico: best online pharmacies in mexico – mexican pharmaceuticals online
Добрый день!
Где приобрести диплом по нужной специальности?
vlasti.biz/202112192678/bor-ba-s-korruptsciei/novosti/kupit-diplom-o-srednem-obrazovanii.html
pharmacies in mexico that ship to usa: medicine in mexico pharmacies – mexico drug stores pharmacies
buying prescription drugs in mexico online: mexico drug stores pharmacies – mexican mail order pharmacies
mexico pharmacies prescription drugs: mexican mail order pharmacies – п»їbest mexican online pharmacies
reputable mexican pharmacies online: mexico pharmacies prescription drugs – best online pharmacies in mexico
mexican border pharmacies shipping to usa mexican online pharmacies prescription drugs medicine in mexico pharmacies
Привет!
Заказать документ института можно в нашей компании в Москве.
ast-diplomas.com/kupit-diplom-sankt-peterburg
Удачи!
создание сайтов на заказ создание сайтов на заказ .
https://mexicandeliverypharma.com/# mexican online pharmacies prescription drugs
Добрый день!
Мы можем предложить дипломы любой профессии по приятным ценам.
horn-fahrzeugaufbereitung.de/купить-дипломы-олимпиад
http://mexicandeliverypharma.com/# buying prescription drugs in mexico
Привет, друзья!
Заказать документ о получении высшего образования вы имеете возможность у нас.
diplomasx.com/kupit-diplom-perm
mexico drug stores pharmacies best online pharmacies in mexico mexican border pharmacies shipping to usa
Здравствуйте!
Всё, что нужно знать о покупке аттестата о среднем образовании без рисков
mans-diploms.ru
Discover Kyrie Irving’s https://mavericks-de-dallas.kyrie-irving-fr.com journey with the Dallas Mavericks, from his early days to forming a power duo with Luka Doncic and competing for a championship.
mexican rx online mexico pharmacy medicine in mexico pharmacies
Hey there! I realize this is kind of off-topic however I had
to ask. Does building a well-established blog such as yours require a lot
of work? I am brand new to writing a blog however
I do write in my journal on a daily basis. I’d like to start a blog
so I can share my experience and feelings online. Please let me know if you have any kind of ideas or tips for brand new aspiring blog owners.
Thankyou!
mexican rx online: buying prescription drugs in mexico online – mexican border pharmacies shipping to usa
medicine in mexico pharmacies: mexico drug stores pharmacies – mexican online pharmacies prescription drugs
medication from mexico pharmacy: medication from mexico pharmacy – reputable mexican pharmacies online
reputable mexican pharmacies online: medicine in mexico pharmacies – buying from online mexican pharmacy
заказать сайт на тильде заказать сайт на тильде .
http://mexicandeliverypharma.com/# п»їbest mexican online pharmacies
https://mexicandeliverypharma.com/# mexican rx online
mexican pharmaceuticals online п»їbest mexican online pharmacies buying from online mexican pharmacy
Привет!
Легальная покупка диплома о среднем образовании в Москве и регионах
gaiassulin.com/диплом-о-среднем-образовании-как-и-где.html
Всегда вам поможем!.
buying prescription drugs in mexico online: buying prescription drugs in mexico online – buying prescription drugs in mexico
purple pharmacy mexico price list: mexico pharmacies prescription drugs – mexican mail order pharmacies
Здравствуйте!
Мы изготавливаем дипломы любой профессии по доступным тарифам.
ciscoworld.de/купить-диплом-о-высшем-образовании-че
mexico pharmacies prescription drugs: mexico drug stores pharmacies – pharmacies in mexico that ship to usa
buying prescription drugs in mexico online: buying from online mexican pharmacy – mexican online pharmacies prescription drugs
mexican pharmaceuticals online п»їbest mexican online pharmacies mexico drug stores pharmacies
Great delivery. Great arguments. Keep up the great work.
Частная платная клиника https://mypsyhealth.ru психиатрии, психологии, психотерапии и наркологии анонимно в Москве.
п»їbest mexican online pharmacies buying prescription drugs in mexico pharmacies in mexico that ship to usa
https://mexicandeliverypharma.com/# buying prescription drugs in mexico online
http://mexicandeliverypharma.com/# mexican rx online