1、定义一个popup页面,样式如下:
<template> <view class="bg-color"> <!--这里放弹窗的具体内容--> <view class="p4" @click="closePopup">关闭弹窗</view> </view> </template> <script> export default { data() { return { } }, methods: { closePopup(){ uni.navigateBack({ delta: 1 }) } } } </script> <style> page { background: transparent; } .bg-color{ position: fixed; top: 0; bottom: 0; left: 0; right: 0; background-color: rgba(0,0,0,.3); } </style>2、在pages.json中将popup定义为页面
"pages": [ { "path": "pages/popup/popup", "style": { "navigationStyle": "custom", "backgroundColor": "transparent", "app-plus": { "animationType": "fade-in", "background": "transparent", "popGesture": "none" } } } ]3、使用方法:
showPopup(){ uni.navigateTo({ url: '/pages/popup/popup', // 可以配合页面打开动画,让弹窗出现的更加个性 // animationType: 'slide-in-bottom', // animationDuration: 150 }); }