Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

vue3页面跳转

作者:浪子罢了   发布日期:2025-05-17   浏览:53

// 使用 Vue Router 实现页面跳转的示例代码

// 1. 首先,确保你已经安装并配置了 Vue Router。
// 在 main.js 中引入并创建路由实例:
import { createApp } from 'vue';
import App from './App.vue';
import { createRouter, createWebHistory } from 'vue-router';
import Home from './views/Home.vue';
import About from './views/About.vue';

const routes = [
  { path: '/', component: Home },
  { path: '/about', component: About }
];

const router = createRouter({
  history: createWebHistory(),
  routes
});

const app = createApp(App);
app.use(router);
app.mount('#app');

// 2. 在组件中使用 <router-link> 或编程式导航进行页面跳转。

// 使用 <router-link> 组件(推荐)
<template>
  <div>
    <router-link to="/">Home</router-link>
    <router-link to="/about">About</router-link>
    <router-view></router-view>
  </div>
</template>

// 编程式导航(在方法中使用 this.$router.push())
<script>
export default {
  methods: {
    goToAbout() {
      this.$router.push({ path: '/about' });
    }
  }
}
</script>

// 以上代码展示了如何在 Vue 3 中配置和使用 Vue Router 进行页面跳转。

上一篇:vue lodash

下一篇:vue3 ssr

大家都在看

vue.config.js configu

node.js vue

vue查看版本

vue等待几秒

vue3 setup computed

vue screenfull

vue json.stringify

vue 遍历list

typescript vue

vue 复选框

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站