<template>
<div>
<button @click="navigateToHome">跳转到首页</button>
</div>
</template>
<script setup>
const navigateToHome = () => {
// 使用路由的 push 方法导航到 /home 路由
this.$router.push('/home');
};
</script>
时代变了,在查询了各种资料后,这玩意是vue2的产物,让我们拥抱,vue3吧。。。
第一步,在script标签补全setup
第二步,定义变量,总结调用router中push方法
第三步,调用
<!--第一步-->
<script setup>
//第二步
import router from '@/router'
// 第三步
const navigateToHome = () => {
// 使用 router 的 push 方法导航到 /LoginIn 路由
router.push('/LoginIn');
};
</script>
或者使用第一套
<router-link><router-link/>进行跳转
<router-view><router-view/>接受跳转页面