一、新建项目Demo2
二、安装 参考文献:Installation | Vue Router
npm install vue-router@4
三、新建目录及页面
/products/index.vue
<template> <h1>产品管理</h1> </template> <script setup> </script> <style> </style>
/merchands/index.vue
<template> <h1>商品管理</h1> </template> <script> </script> <style> </style>
四、修改
index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link href="/favicon.ico" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Vite App</title> <script type="module" src="/src/main.js"></script> </head> <body> <div id="app"> </div> </body> </html>
App.vue
<script setup> </script> <template> <img alt="Vue logo" src="./assets/logo.png" alt="vue3-VueRouter使用" /> <p> <router-link to="/">P</router-link> <router-link to="/m" style="margin-left: 20px;">M</router-link> </p> <router-view></router-view> </template> <style> #app { text-align: center; color: #2c3e50; margin-top: 60px; } </style>
main.js
import { createApp } from 'vue' import * as VueRouter from 'vue-router'; import App from './App.vue' import Product from './products/index.vue' import Merchands from './merchands/index.vue' const routes = [ { path: '/', component: Product }, { path: '/m', component: Merchands }, ] const router = VueRouter.createRouter({ // 4. 内部提供了 history 模式的实现。为了简单起见,我们在这里使用 hash 模式。 history: VueRouter.createWebHashHistory(), routes, // `routes: routes` 的缩写 }) createApp(App).use(router).mount('#app')
五、效果
热门文章
- 宠物粮厂利润怎么样呀(宠物粮厂利润怎么样呀)
- 动物注射疫苗简报怎么写好看(兽医打疫苗简报)
- 记-Windows环境下Prometheus+alertmanager+windows_exporter+mtail监控部署提起网关日志
- 南京领养狗狗的平台叫什么(南京免费领养狗狗正规网站平台)
- 宠物粮食加工厂挣钱吗现在怎么样(小型宠物粮加工厂需要什么手续)
- 「4月4日」最高速度21.9M/S,2025年Shadowrocket/Clash/V2ray/SSR每天更新免费节点订阅地址分享
- 广州领养狗狗的平台(广州领养狗狗的平台叫什么)
- 「3月6日」最高速度21.1M/S,2025年Clash/Shadowrocket/SSR/V2ray每天更新免费节点订阅地址分享
- 动物打了疫苗有什么用(动物打防疫针)
- 「4月14日」最高速度19M/S,2025年V2ray/Clash/SSR/Shadowrocket每天更新免费节点订阅地址分享