目录
安装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
amoxicillin 500 mg cost: can you buy amoxicillin over the counter – amoxacillian without a percription
where to get generic clomid without prescription: can i purchase generic clomid online – can you get cheap clomid without insurance
https://doxycyclinedelivery.pro/# pharmacy prices for doxycycline
Добрый день!
Купить документ о получении высшего образования можно в нашем сервисе.
ast-diplomas.com/kupit-diplom-sankt-peterburg
Хорошей учебы!
Добрый день!
Мы готовы предложить дипломы психологов, юристов, экономистов и других профессий по доступным ценам.
http://www.horn-fahrzeugaufbereitung.de/диплом-купить-е.html
FC Barcelona https://spain.fc-barcelona-ar.com is undoubtedly one of the most famous and well-known football clubs in the world.
https://paxloviddelivery.pro/# buy paxlovid online
порно видео онлайн порно видео онлайн .
порно коллекции бесплатно https://porn-library.ru .
lees hier
Al-Ittihad https://saudi.al-ittihad-ar.com is one of the most famous football clubs in Saudi Arabia. Founded in 1927, the Saudi football giant has come a long way to the pinnacle of success.
Al-Nasr Club https://saudi.al-hilal-ar.com from Riyadh has a rich history of success, but its growth has been particularly impressive in recent years.
https://clomiddelivery.pro/# cost generic clomid pill
Al-Nasr https://saudi.al-nassr-ar.com is one of the most famous football teams in the Kingdom of Saudi Arabia.
онлайн порно видео онлайн порно видео .
Luis Suarez https://inter-miami.luis-suarez-ar.com the famous Uruguayan footballer, ended his brilliant career in European clubs and decided to try his hand at a new challenge – Major League Soccer.
http://ciprodelivery.pro/# buy cipro online without prescription
Привет, друзья!
Где заказать диплом специалиста?
Заказать диплом любого университета.
comedyforme.ru/legalnyiy-diplom-bez-lishnih-voprosov
порно коллекция порно коллекция .
порево классный секс klassny-sex.ru .
paxlovid price: paxlovid pill – paxlovid price
can you buy cheap clomid without dr prescription: where can i get generic clomid no prescription – can i buy clomid without prescription
смотреть классное порево смотреть классное порево .
Добрый день!
Мы изготавливаем дипломы любых профессий по невысоким тарифам.
jrsjewellers.com/2024/06/29/купить-дипломы-университета/
грузовые подъемники спб https://podemniki-gruzovye.ru
Добрый день!
Мы готовы предложить документы техникумов, расположенных в любом регионе РФ. Можно заказать диплом за любой год, включая документы старого образца. Дипломы и аттестаты выпускаются на “правильной” бумаге высшего качества. Это позволяет делать настоящие дипломы, которые невозможно отличить от оригинала. Документы заверяются необходимыми печатями и подписями.
rm7s812fz.wizzardsblog.com/28306958/%D0%9A%D0%B0%D0%BA-%D0%B2%D0%BE%D0%B7%D0%BC%D0%BE%D0%B6%D0%BD%D0%BE-%D0%B1%D1%8B%D1%81%D1%82%D1%80%D0%BE-%D0%BA%D1%83%D0%BF%D0%B8%D1%82%D1%8C-%D0%B4%D0%B8%D0%BF%D0%BB%D0%BE%D0%BC-%D0%B2-%D0%BE%D0%BD%D0%BB%D0%B0%D0%B9%D0%BD-%D0%BC%D0%B0%D0%B3%D0%B0%D0%B7%D0%B8%D0%BD%D0%B5
Bayern Munich’s https://bayern.jamal-musiala-ar.com young midfielder, Jamal Musiala, has become one of the brightest talents in European football.
Thibaut Courtois https://real-madrid.thibaut-courtois-ar.com was born on May 11, 1992 in Belgium.
https://amoxildelivery.pro/# amoxicillin 250 mg price in india
https://clomiddelivery.pro/# cost clomid without a prescription
https://paxloviddelivery.pro/# paxlovid pharmacy
paxlovid cost without insurance: paxlovid covid – buy paxlovid online
http://doxycyclinedelivery.pro/# doxycycline prices australia
paxlovid india: paxlovid covid – paxlovid price
смотреть классное порево смотреть классное порево .
Arsenal https://arsenal.mesut-ozil-ar.com made a high-profile signing in 2013, signing star midfielder Mesut Ozil from Real Madrid.
In an era when many young footballers struggle to find their place at elite clubs, Javi’s https://barcelona.gavi-ar.com story at Barcelona stands out as an exceptional one.
Rodrigo Goes https://real-madrid.rodrygo-ar.com better known as Rodrigo, is one of the brightest young talents in modern football.
The Saudi Football League https://saudi-arabian-championship.saudi-pro-league-ar.com known as the Saudi Professional League, is one of the most competitive and dynamic leagues in the world.
https://euroavia24.com – Cheap flights, hotels and transfers around the world!
https://paxloviddelivery.pro/# paxlovid for sale
Здравствуйте!
Заказать диплом о высшем образовании.
ekonomimvmeste.ukrbb.net/viewtopic.php?f=8&t=25826
Удачи!
Привет, друзья!
Приобрести документ о получении высшего образования можно у нас в Москве.
diploms-x.com/kupit-diplom-magistra
Удачи!
Привет!
Официальная покупка диплома вуза с сокращенной программой в Москве
arusak-diploms-srednee.ru/kupit-diplom-magistra В
In recent years, the leading positions in the Spanish https://spanish-championship.laliga-ar.com championship have been firmly occupied by two major giants – Barcelona and Real Madrid.
https://amoxildelivery.pro/# amoxicillin buy online canada
In the German football https://german-championship.bundesliga-football-ar.com championship known as the Bundesliga, rivalries between clubs have always been intense.
The Italian football championship https://italian-championship.serie-a-ar.com known as Serie A, has seen an impressive revival in recent years.
The road to the Premier League https://english-championship.premier-league-ar.com begins long before a team gets promoted to the English Premier League for the first time
https://doxycyclinedelivery.pro/# buy doxycycline 100mg online