位置:- 正文

vue跳转页面(vue跳转页面的几种方法)

编辑:rootadmin

vue怎么跳转页面呢?不知道的小伙伴来看看小编今天的分享吧!
613/auto1686643497vue跳转页面(vue跳转页面的几种方法)

vue有三种不同方式实现页面跳转。

方法一:Vue:router-lin

<router-link to="/">[跳转到主页]</router-link>

<router-link to="/login">[登录]</router-link>

<router-link to="/logout">[登出]</router-link>

方法二:this.$router.push("/");

<button @click="goHome">[跳转到主页]</button>

export default {

name: "App",

methods: {

// 跳转页面方法

goHome() {

this.$router.push("/");

},

}

方法三:this.$router.go(1);

<button @click="upPage">[上一页]</button>

<button @click="downPage">[下一页]</button>

upPage() {

// 后退一步记录,等同于 history.back()

this.$router.go(-1);

},

downPage() {

// 在浏览器记录中前进一步,等同于 history.forward()

this.$router.go(1);

}

代码示例:

<template>

<div id="app">

<img src="./assets/logo.png">

<router-view/>

<router-link to="/">[跳转到主页]</router-link>

<router-link to="/login">[登录]</router-link>

<router-link to="/logout">[登出]</router-link>

<!-- javascript跳转页面 -->

<button @click="goHome">[跳转到主页]</button>

<!-- 回到上一页 -->

<button @click="upPage">[上一页]</button>

<button @click="downPage">[下一页]</button>

<!-- 回到下一页 -->

</div>

</template>

<script>

export default {

name: "App",

methods: {

// 跳转页面方法

goHome() {

this.$router.push("/");

},

upPage() {

// 后退一步记录,等同于 history.back()

this.$router.go(-1);

},

downPage() {

// 在浏览器记录中前进一步,等同于 history.forward()

this.$router.go(1);

}

}

};

</script>

以上就是小编今天的分享了,希望可以帮助到大家。

本文链接地址:https://www.jiuchutong.com/zhishi/2690.html 转载请保留说明!
下一篇链接:https://www.jiuchutong.com/zhishi/2691.html
免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络