uni-app 遮罩模板

1. common新建mask.vue文件。

<template>  
    <view>  
        <view class="cpt-mask">  
        </view>  
    </view>  
</template>  

<script>  
    export default {
       
    }  
</script>  

<style>  
    .cpt-mask {  
        position: fixed;  
        top: 0;  
        left: 0;  
        width: 100%;  
        height: 100%;  
        background-color: rgba(0,0,0,0.5);  
        opacity: 0.5;  
        z-index: 99;  
    }  
</style>

 

2. 引入mask.vue文件。

<template>
    <view>
        <!-- 关闭遮罩 -->
        <view @click="remove(false)"> 
            <!-- 遮罩组件 -->
            <Mask v-if="mask"></Mask> 
        </view>  
        <view class="masks">
            <button type="primary" @click="remove(true)">显示遮罩</button>
        </view>
    </view>
</template>
<script>
    import Mask from '../../common/mask.vue';
    export default {
    components: {
        Mask
    },
    data() {
        return {
            mask: false
        }
    },
    methods: {
        remove (mask) {
            this.mask =  mask;
        }
    }
}
</script>
 
<style lang="less">
    page {
      background: #f8f8f8;
    }
  .masks {
        position: absolute;
        bottom: 0;left: 50%-100rpx;right: 50%-100rpx;
    }
</style>

  

posted @ 2020-01-03 13:16  本溢  阅读(10288)  评论(3编辑  收藏  举报