Vue实现基本组件的方法-从最简单的弹窗开始

2 篇文章 0 订阅

前言

项目中基本上都会用到灰色模态框,最基本的就是登陆登出界面,本文会从最简单的一个遮罩组件做起。

效果图

在这里插入图片描述

实现步骤

1.实现html和css样式

2.子组件的vue代码

3.父组件的vue代码

1.实现html和css样式

html如下
<div class="modal" v-show="showModal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="close-modal">
                    <solt></solt>
                    <Icon type="md-close" @click="closeMyself"/>
                </div>
            </div>
        </div>
    </div>
CSS如下
<style lang="stylus" scopced>

.modal
    display flex
    align-items center
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1050;
    outline: 0;
    &:before
        content: "";
        display: block;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: #171e26;
        opacity: .9;
        -webkit-transition: opacity .3s ease-out;
        transition: opacity .3s ease-out;
    .modal-dialog
        width: auto;
        margin: 0 auto;
        transform: none;
        position: relative;
.modal-content
    border-radius: 0;
    border: none;
    -webkit-box-shadow: none;
    box-shadow: none;
    background-color: transparent;
    min-height: 380px;
    position: relative;
    background-clip: padding-box;
.close-modal
    position: fixed;
    right: 45px;
    top: 35px;
    border-radius: 30px;
    padding: 12px 12px;
    color: hsla(0,0%,100%,.9);
    background-color: hsla(0,0%,100%,.25);
    transition: all .4s;
    &:hover
        background hsla(0,0%,100%,.35)
        cursor pointer
    i
        font-size 20px
</style>

2.子组件的vue代码

props:{
        showModal: {
            default: true,
            type: Boolean,
            required: true
        }
    },
    methods: {
        closeMyself() {
            this.$emit("on-close")
        }
    }

3.父组件的vue代码

<modal-window :showModal="showModal" @on-close="closeDialog"></modal-window>

data() {
    return {
        showModal: false,//遮罩面板
    }
    
closeDialog() {
    this.showModal = false
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值