基于element封装下 弹窗

基础层:dialog

<!-- 自定义弹窗模板 -->
<template>
    <el-dialog
        v-bind="$attrs"
        :close-on-click-modal="$attrs['close-on-click-modal'] ? $attrs['close-on-click-modal'] : false"
        :close-on-press-escape="$attrs['close-on-press-escape'] ? $attrs['close-on-press-escape'] : false"
        v-on="$listeners"
        
    >
      <!-- <slot name="dialog" /> -->
      <slot name="body" />
      <template slot="footer">
        <slot name="footer" />
      </template>
    </el-dialog>
</template>

<script>
export default {
  name: "dialog",
  mounted() {
    //初始化title,防止冲突
    this.$el.title="";
  },
};
</script>
<style lang='scss' scoped>
.flexFooter{
    display: flex;
    justify-content: flex-end;
}
</style>

引用 逻辑层:

<!--  -->
<template>
  <Dialog :visible="visible" :title="info.title" width="400px" @close="closeDialog">
        <div slot="body">
           <div class="message"  ><span>{{info.message}}</span></div>
        </div>
        <div slot='footer' class="flexFooter">
            <button type="button" class="z-button mr20" @click="closeDialog">取消</button>
            <button type="button" class="z-button-warning" @click="onSuccess" v-if="warning">确定</button>
            <button type="button" class="z-button-primary" @click="onSuccess" v-if="!warning">确定</button>
        </div>
    </Dialog>
</template>

<script>
export default {
    name:'title',
    components: {
        Dialog:resolve => resolve(require("./dialog"))
    },
    props:{
        info:{
            type:Object,
            default:{title:'提示'}
        },
        visible:{
            type:Boolean,
            default:false
        },
        warning:{
            type:Boolean,
            default:false
        }
    },
    data () {
        return {
            
        };
    },

    computed: {},

    created() {
    },

    methods: {
        closeDialog(){
            this.$emit("update:visible",false)
        },
        onSuccess(){
            this.$emit("onSuccess")
        }
    }
}

</script>
<style lang='scss' scoped>
.message{
  display: flex;
  align-items: center;
  height:140px
}
</style>

二级弹窗

<!--  -->
<template>
  <Dialog :visible="visible" :title="info.title" width="400px" @close="closeDialog">
        <div slot="body">
		        <el-dialog
				      width="30%"
				      title="内层 Dialog"
				      :visible.sync="innerVisible"
				      append-to-body>
				    </el-dialog>
				    <div slot="footer" class="dialog-footer">
				      <el-button @click="outerVisible = false">取 消</el-button>
				      <el-button type="primary" @click="innerVisible = true">打开内层 Dialog</el-button>
				    </div>
				  </el-dialog>
		           <div class="message"  ><span>{{info.message}}</span></div>
        </div>
        <div slot='footer' class="flexFooter">
            <button type="button" class="z-button mr20" @click="closeDialog">取消</button>
            <button type="button" class="z-button-warning" @click="onSuccess" v-if="warning">确定</button>
            <button type="button" class="z-button-primary" @click="onSuccess" v-if="!warning">确定</button>
        </div>
    </Dialog>
</template>

<script>
export default {
    name:'title',
    components: {
        Dialog:resolve => resolve(require("./dialog"))
    },
    props:{
        info:{
            type:Object,
            default:{title:'提示'}
        },
        visible:{
            type:Boolean,
            default:false
        },
        warning:{
            type:Boolean,
            default:false
        }
    },
    data () {
        return {
            
        };
    },

    computed: {},

    created() {
    },

    methods: {
        closeDialog(){
            this.$emit("update:visible",false)
        },
        onSuccess(){
            this.$emit("onSuccess")
        }
    }
}

</script>
<style lang='scss' scoped>
.message{
  display: flex;
  align-items: center;
  height:140px
}
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值