Vue 中 div 元素跳转的方法有两种:使用 Vue Router,添加 router-link 组件。添加 @click 事件监听器,调用 this.$router.push() 方法跳转。

方法一:使用 Vue Router
Vue Router 是 Vue.js 官方推荐的路由库,用于管理单页面应用程序中的路由。通过使用 router-link 组件,可以在 div 元素上添加一个跳转链接:
<code class="html"><template>
<div>
<router-link to="/about">关于我们</router-link>
</div>
</template>
<script>
import { router } from '@/router'
</script></code>方法二:使用 @click 事件监听器
可以在 div 元素上添加一个 @click 事件监听器,在触发时使用 this.$router.push() 方法跳转到指定的 URL:
立即学习“前端免费学习笔记(深入)”;
<code class="html"><template>
<div @click="goToAbout">关于我们</div>
</template>
<script>
import { router } from '@/router'
export default {
methods: {
goToAbout() {
this.$router.push('/about')
}
}
}
</script></code>如何选择方法
@click 事件监听器更简洁易用。以上就是vue的div怎么跳转的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号