当前位置:网站首页>H5 van-popup全屏弹窗,模拟页面回退效果,支持左上角返回按钮,适用物理返回,侧滑与底部返回键
H5 van-popup全屏弹窗,模拟页面回退效果,支持左上角返回按钮,适用物理返回,侧滑与底部返回键
2022-06-10 19:29:00 【小半Annie】
第一步:
1、定义animateDuration变量
2、定义open事件执行方法selectProjectOpenHandler
3、定义close事件执行方法selectProjectCloseHandler
data () {
return {
animateDuration: 0.3 // 默认弹窗动画时间0.3s
}
},
第二步:van-popup使用:
<!-- van-popup -->
<van-popup
v-model="_show"
position="right"
:overlay="false"
:style="{ width: '100%', height: '100%' }"
:duration="animateDuration"
@open="selectProjectOpenHandler"
@close="selectProjectCloseHandler">
<!-- 弹窗内容 -->
</van-popup>
第三步:
selectProjectOpenHandler:
// popup打开
selectProjectOpenHandler () {
window.history.pushState(null, null, '#') // 模拟新的一页history记录
window.addEventListener('popstate', this.popstateHandler) //添加popstate事件监听
}
popstateHandler (e) {
this.animateDuration = 0 // 防止侧滑出现多次动画
this._show = false //关闭van-popup
}
selectProjectCloseHandler:
// popup关闭
selectProjectCloseHandler () {
window.removeEventListener('popstate', this.popstateHandler, false)
},
第四步:按钮返回的方法goBack (重要!)
goBack () {
window.history.back() // 删掉van-popup打开时添加的history
this._show = false
},
效果杠杠的!!!具体的业务需求可以自行调整哈
边栏推荐
- 一个10年左右的老程序员说:简单CRUD功能进入无码开发时代1 之 增删改查接口信息
- 最近的工作
- Tencent cloud database tdsql- a big guy talks about the past, present and future of basic software
- Jiangbolong forestee xp2000 PCIe 4.0 SSD multi encryption function, locking data security
- Zabbix_ Monitoring ssh/crond Service - wechat alarm
- [FAQ] summary of common problems and solutions during the use of rest API interface of sports health service
- 软件定义边界(SDP)
- Hm3416h buck IC chip pwm/pfm controls DC-DC buck converter
- Flutter series: UI layout introduction
- 国庆期间给大家推荐一个可能会成为2019最佳的CRUD工具
猜你喜欢

「Bug」问题分析 RuntimeError:which is output 0 of ReluBackward0

观点丨Play and Earn 会让加密游戏误入歧途

Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data

LLDP协议编写要点

Microsoft Word 教程「5」,如何在 Word 中更改頁邊距、創建新聞稿欄?

Microsoft Word 教程「5」,如何在 Word 中更改页边距、创建新闻稿栏?

SBC chip 35584 data manual pre regulator translation

First batch! Sinomenine has passed CWPP capability assessment and inspection of Xintong Institute

C (pointer 02)

FPGA状态机
随机推荐
Solution to the problem that JLINK CDC UART driver cannot be installed normally under win7 system
Fs2117 boost IC output 5v2.4a synchronous rectification
table设置超出部分隐藏,鼠标移上去显示全部
安全隐患?意义有限?挡不住真煮迷你厨具火爆618
latex tips 绝对值的竖线 \left|\right|
Fs4521 constant voltage linear charging IC
Redis cluster form - sentry mode cluster and high availability mode cluster - redis learning notes 003
Uni app custom navigation
LLDP协议编写要点
The old programmer said: stop translating the world, developers should return to programming
20192407 2021-2022-2 《网络与系统攻防技术》实验八实验报告
Standing at such a time node today, we may have a clearer understanding of the industrial Internet
During the college entrance examination this year, all examination sites were in good order, and no sensitive cases affecting safety occurred
C (pointer 02)
利用阿里云国际购买的服务器搭建个人网站步骤
Zabbix_原理架构-安装部署-自定义监控
传音 Infinix 新机现身谷歌产品库,TECNO CAMON 19 预装 Android 13
ZABBIX server trapper Remote Code Execution Vulnerability (cve-2017-2824)
How to realize face verification quickly and accurately?
C pointer (interview classic topic exercise)