router-link
时间: 2023-09-11 10:05:03 浏览: 77
The router-link is a component in Vue.js that provides a declarative way to navigate between pages in a single-page application using the Vue Router. It is used to create links that trigger a navigation to a specified URL when clicked. The router-link component is similar to the HTML anchor tag but with additional functionality provided by the Vue Router.
The router-link component has several props that can be used to customize its behavior, such as the "to" prop which specifies the target URL and the "tag" prop which specifies the HTML tag to be used for the link. It also supports dynamic routing by allowing the "to" prop to be bound to a data property or computed property.
Here is an example of how to use the router-link component in Vue.js:
```
<template>
<div>
<router-link to="/">Home</router-link>
<router-link to="/about">About</router-link>
<router-link :to="{ name: 'user', params: { userId: 123 }}">User Profile</router-link>
</div>
</template>
```
In this example, we have three router-link components that create links to the Home, About, and User Profile pages respectively. The User Profile link uses a named route and passes a parameter to it. When any of these links are clicked, the Vue Router will navigate to the corresponding page without a full page reload.
阅读全文