Vue路由跳转(一)

本文详细介绍如何使用 vue-router 进行项目路由配置,包括安装、导入、配置路由规则、实例化及挂载等步骤,并演示了如何在项目中具体实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、装路由:`

cnpm install vue-router --save `

运行项目:

cnpm run dev

项目运行完成后可看到路由版本:
在这里插入图片描述

2、main.js(主入口)里进行以下操作(路由的导入、使用、配置、实例化、挂载):
【本例背景组件以My.vue和Home.vue为例】

//引入组件
import My from ‘./Components/My.vue’
import Home from ‘./Components/Home.vue’
//导入路由
import VueRouter from ‘vue-router’;
//使用路由
Vue.use(VueRouter);
//配置
const routes=[
{ path:"/",component:Home},
{path:"/My",component:My}
]
//实例化
const router=new VueRouter({
routes:routes,
mode:“history”
});
// 在Vue实例上挂载
new Vue({
el:’#app’,
router, //在实例化里用router
render:h=>h(App)
})

mode:"history" 是把链接里的#去掉
3、在根组件App.vue里写路由出口点

<router-view> </router-view>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值