vue二次封装el-dialog组件

<template>
  <el-dialog :title="title" :visible.sync="tDialogVisible" :width="width" @open="open"
    @closed="dialogClose" :append-to-body="appendToBody" :fullscreen="fullscreen" :top='top'
    :modal='modal' @before-close='beforeClose' :center='center'
    :close-on-click-modal='closeOnClickModel' @close="close">
    <slot></slot>
    <span slot="footer" class="dialog-footer">
      <el-button @click="tDialogVisible = false" v-if="showCancel">取 消</el-button>
      <el-button type="primary" @click="submit" v-if="showSubmit">确 定</el-button>
    </span>
  </el-dialog>

</template>

<script>
export default {
  data() {
    return {
      tDialogVisible: this.dialogVisible,
    };
  },
  props: {
    dialogVisible: {
      default: false,
    },
    width: {
      default: '65%'
    },
    title: {
      default: '标题'
    },
    showCancel: {
      default: true
    },
    showSubmit: {
      default: true
    },
    appendToBody: {
      default: false
    },
    fullscreen: {
      default: false
    },
    top: {
      default: '15vh'
    },
    modal: {
      default: true
    },
    center: {
      default: false
    },
    closeOnClickModel: {
      default: true
    }
  },
  watch: {
    dialogVisible: function (n) {
      this.tDialogVisible = n;
    },

    tDialogVisible(n){
      this.$emit('update:dialogVisible',n)
    }


    
  },
  methods: {
    open() {
      this.$emit('open')
    },
    dialogClose() {
      this.$emit('closed')
    },
    beforeClose() {
      this.$emit('beforeClose')
    },
    close(){
      this.$emit('close')
    },
    submit(){
      this.$emit('submit')
    }
  },
};
</script>

<style lang='scss' scoped>
</style>

注册成全局组件

import dcDialog from '@/components/dcDialog/dcDialog'

Vue.component('dcDialog',dcDialog) 

注册完成即可使用

<dc-dialog></dc-dialog>

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值