1.首先进行安装vue-router
npm install vue-router
2.在项目组件中引入
import { useRouter } from "vue-router";
3.使用userRouter进行方法中跳转路由
const router = useRouter();
const handleHome=()=>{
router.push("/home");
}
4.完整代码
<template>
<div class="app">
<button @click="handleHome">登录</button>
</div>
</template>
<script setup>
import { useRouter } from "vue-router";
const router = useRouter();
const handleHome=()=>{
router.push("/home");
}
</script>
<style lang="scss" scoped>
</style>