router-link和a标签

<template>
	<router-link to="/link">跳转</router-link>
	<a href="/link" @click="handleTo">跳转</a>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'
const $router = useRouter()
const handleTo = (event) => {
// 模拟router-link
  event.preventDefault()
  $router.push({ path: event.target.pathname })
}
</script>

你可能感兴趣的:(前端,javascript,开发语言)