二次封装Dialog

64 阅读1分钟
<template>
  <el-dialog
    :visible="dialogVisible"
    :title="title"
    :close-on-click-modal="true"
    :destroy-on-close="true"
    @close="cancel"
    :width="width"
  >
    <slot> </slot>
    <span slot="footer">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="submit">保存</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    title: { type: String },
    width: { type: String, default: "500px" },
  },
  computed: {
    dialogVisible: {
      get() {
        return this.visible;
      },
      set(v) {
        this.$emit("update:visible", v);
      },
    },
  },
  data() {},
  created() {},
  methods: {
    submit() {
      this.$emit("submit");
    },
    cancel() {
      this.dialogVisible = false;
    },
  },
};
</script>

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