怎么链接跳转到别的vue组件
时间: 2023-09-15 08:18:36 浏览: 52
在 Vue.js 中,你可以通过使用 `router-link` 组件来实现路由跳转,将其放在需要点击跳转的元素上即可。具体步骤如下:
1. 在 Vue 实例中,配置路由,例如:
```javascript
import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home'
import About from '@/components/About'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/about',
name: 'About',
component: About
}
]
})
```
2. 在需要点击跳转的元素上使用 `router-link` 组件,例如:
```html
<router-link to="/">Home</router-link>
<router-link to="/about">About</router-link>
```
其中,`to` 属性指定了需要跳转的路由路径。
3. 在需要展示的组件中使用 `router-view` 组件来展示路由对应的组件,例如:
```html
<template>
<div>
<h1>About</h1>
<p>This is the About page.</p>
</div>
</template>
```
这样就可以实现在不同的 Vue 组件之间进行路由跳转了。