x***@126.com
x***@126.com
  • 发布:2019-10-01 09:14
  • 更新:2024-03-27 09:25
  • 阅读:16361

uni-app自定义模态对话框uniPop组件

分类:uni-app

基于UniApp自定义弹出框uniPop组件、实现了uniapp仿微信、android、ios弹窗效果

uniPop组件含有多种动画效果、皮肤类型ios/android、可以自定义弹窗样式/自定义多按钮及事件/弹窗显示位置、自动关闭秒数、遮罩层透明度及点击遮罩是否关闭

如下图:H5/小程序/App三端效果兼容性一致。(后续大图均展示App端)

uniPop组件引入方式
以下两种引入方式均可:

  • 在main.js里引入全局组件
    import uniPop from './components/uniPop/uniPop.vue'
    Vue.component('uni-pop', uniPop)
  • 在页面引入组件
<template>  
    <view class="container">  
        ...  

        <!-- 弹窗模板 -->  
        <uni-pop ref="uniPop"></uni-pop>  
    </view>  
</template>  

<script>  
    import uniPop from './components/uniPop/uniPop.vue'  
    export default {  
        data() {  
            return {  
                ...  
            }  
        },  
        components:{  
            uniPop  
        },  
        ...  
    }  
</script>

调用方式 this.$refs.uniPop.show({...})

this.$refs.uniPop.show({  
    content: 'msg消息提示框(5s后窗口关闭)',  
    shade: true,  
    shadeClose: false,  
    time: 5,  
    anim: 'fadeIn',  
})

uniPop.vue自定义弹窗模板

/**  
  * @tpl        uni-app自定义弹窗组件 - uniPop.vue  
  * @author     andy by 2019-09-20  
  * @about      Q:282310962  wx:xy190310  
  */  

<template>  
    <view v-if="opts.isVisible" class="uniPop" :class="opts.isCloseCls">  
        <view class="unipop__ui_panel">  
            <view v-if="opts.shade" class="unipop__ui_mask" @tap="shadeTaped"></view>  
            <view class="unipop__ui_main">  
                <view class="unipop__ui_child" :style="opts.style">  
                    <!-- 标题 -->  
                    <view v-if="opts.title" class="unipop__ui_tit">{{opts.title}}</view>  
                    <!-- 内容 -->  
                    <view v-if="opts.content" class="unipop__ui_cnt" :style="opts.contentStyle">  
                        {{opts.content}}  
                    </view>  
                    <view v-if="opts.btns" class="unipop__ui_btns">  
                        <text v-for="(item,index) in opts.btns" :key="index" class="btn" :style="item.style" @tap="btnTaped(item)">{{item.text}}</text>  
                    </view>  
                </view>  
                <!-- xclose -->  
                <view v-if="opts.xclose" class="unipop__xclose" @tap="close"></view>  
            </view>  
        </view>  
    </view>  
</template>
data() {  
    return {  
        defaultOptions: {  
            isVisible: false,       //是否显示弹窗  

            title: '',              //标题  
            content: '',            //内容  
            contentStyle: '',       //内容样式  
            style: null,            //自定义弹窗样式  
            skin: '',               //弹窗风格  
            icon: '',               //弹窗图标  
            xclose: false,          //自定义关闭按钮  

            shade: true,            //遮罩层  
            shadeClose: true,       //点击遮罩关闭  
            opacity: '',            //遮罩透明度  
            time: 0,                //自动关闭秒数  
            end: null,              //销毁弹窗回调函数  

            anim: 'scaleIn',        //弹窗动画  scaleIn(默认) | fadeIn | shake | top | right | bottom | left  
            position: '',           //弹窗位置  top | right | bottom | left  

            btns: null,             //弹窗按钮  
        },  
        opts: {},  
        timer: null  
    }  
},

作者:xiaoyan2015
链接: https://cloud.tencent.com/developer/column/3374
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

3 关注 分享
ai666 w***@qq.com bzliukai

要回复文章请先登录注册

1***@qq.com

1***@qq.com

请问uniPop. vue在哪下载?
2020-02-27 13:27
l***@qq.com

l***@qq.com

怎么下载
2019-12-08 00:25
2***@qq.com

2***@qq.com

哪里下载
2019-12-01 20:27
小朋友

小朋友

在哪下载?
2019-11-28 11:19
天机不可泄露

天机不可泄露

在哪下载?
2019-11-28 09:50
zhuan888

zhuan888

在哪下载?
2019-10-31 21:58
vandles

vandles

样式呢?从哪下载 啊?
2019-10-27 10:58
星际穿越

星际穿越

啦啦啦啦
2019-10-04 12:54
启程588

启程588

看着不错,留个脚印
2019-10-03 19:05
7***@qq.com

7***@qq.com

可以麻烦作者把插件放到插件市场吗?谢谢
2019-10-03 15:50