在Vue 3中,有多種方式可以實(shí)現(xiàn)頁面跳轉(zhuǎn)。以下是一些常見的方式和相應(yīng)的代碼示例:
1. 使用路由導(dǎo)航(Vue Router)進(jìn)行頁面跳轉(zhuǎn):

// 在路由配置文件中定義路由
import { createRouter, createWebHistory } from 'vue-router';

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

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

// 在組件中使用路由導(dǎo)航
<template>
  <button @click="goToAbout">Go to About</button>
</template>

<script>
import { useRouter } from 'vue-router';

export default {
  methods: {
    goToAbout() {
      const router = useRouter();
      router.push('/about');
    },
  },
};
</script>

2. 使用`<router-link>`組件進(jìn)行頁面跳轉(zhuǎn):

<template>
  <router-link to="/about">Go to About</router-link>
</template>

3. 使用`window.location`進(jìn)行頁面跳轉(zhuǎn):

<template>
  <button @click="goToAbout">Go to About</button>
</template>

<script>
export default {
  methods: {
    goToAbout() {
      window.location.href = '/about';
    },
  },
};
</script>

4. 使用`<a>`標(biāo)簽進(jìn)行頁面跳轉(zhuǎn):

<template>
  <a href="/about">Go to About</a>
</template>

這些是一些常見的頁面跳轉(zhuǎn)方式,你可以根據(jù)具體的需求選擇適合的方式來實(shí)現(xiàn)頁面跳轉(zhuǎn)。