【vue页面,公共按钮,点击返回上一页】

一、问题:

当每个页面都需要一个返回按钮时,为了提高效率 ,可以在App.vue页面写一个公共的,这样就可以在每个页面显示了。
在这里插入图片描述

二、具体代码:

1.html代码:

<template>
	<div id="app">
		<!-- 1.当某一个页面不想引入这个公共组件,用v-show判断路由 -->
		<div class="return_btn" @click="ruturnBtn()" 
			v-show="!(path ==='/pc_hospitalData') && !(path ==='/pc-headquarters')">
			返回
		</div>
	</div>
</template>

2.js代码:

//2.当某一个页面不想引入这个公共组件
mounted() {
	this.path = this.$route.path;
	// console.log(this.$route.path)
},
watch: {
	$route(to, from) {
		this.path = to.path
	}
},

//点击返回上一页(如果没有上一页,默认返回首页)
methods: {
	ruturnBtn() {
		if (window.history.length <= 1) {
			this.$router.push({
				path: '/'
			})
			return false
		} else {
			this.$router.go(-1)
		}
	},
}

3.css代码:

.return_btn {
		width: 90px;
		height: 90px;
		border-radius: 50%;
		background-color: #4C8CFD;
		display: flex;
		align-items: center;
		justify-content: center;
		position: fixed;
		z-index: 999;
		bottom: 150px;
		right: 30px;
		color: #fff;
		font-size: 20px;
	}

ending~

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值