当前位置:   article > 正文

自定义Dialog弹窗_el-form-item内自定义选择弹框组件

el-form-item内自定义选择弹框组件

自定义Dialog弹窗

dialog组件

<!-- dialogCom.vue -->
<template>
  <div class="dialogView" v-if="dialogVisible">
    <div class="dialogContent">
      <div class="title">
        <span>{{ title }}</span>
        <!-- <i @click="close" style="cursor: pointer" class="el-icon-close"></i> -->
        <el-icon @click="close" style="cursor: pointer"><CloseBold /></el-icon>
      </div>
      <div>内容</div>
      <div class="footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="confirm">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, reactive, Ref, toRefs } from "vue";
import { CloseBold } from "@element-plus/icons-vue";

export default defineComponent({
  name: "pageEleven",
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    title: {
      type: String,
      default: "标题",
    },
  },
  components: { CloseBold },
  emits: ["closeFun"],
  setup(props, { emit }) {
    const dialogVisible: Ref = computed(() => {
      return props.visible;
    });
    const state = reactive({});
    function close() {
      emit("closeFun", false);
    }
    function confirm() {
      emit("closeFun", false);
    }
    return {
      dialogVisible,
      ...toRefs(state),
      close,
      confirm,
    };
  },
});
</script>

<style lang='scss' scoped>
.dialogView {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 101;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.25);
  .dialogContent {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 500px;
    height: 556px;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 10px;
    padding: 10px;
    .title {
      height: 30px;
      font-size: 16px;
      font-weight: 600;
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 10px;
    }
    .footer {
      position: absolute;
      bottom: 0;
      right: 0;
      height: 45px;
      margin-right: 20px;
    }
  }
}
</style>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95

使用

<template>
  <div class="pageEleven">
    <el-button @click="visible = true">打开dialog</el-button>
 	 <!-- dialog自定义组件使用 -->
    <DialogComVue :title="title" :visible="visible" @closeFun="closeFun" />
  </div>
</template>

<script lang="ts">
import { defineAsyncComponent, defineComponent, reactive, toRefs } from "vue";
export default defineComponent({
  name: "pageEleven",
  components: {
    DialogComVue: defineAsyncComponent(() => import("@/components/dialogCom.vue")),
  },
  setup() {
    const state = reactive({
      title: "Dialog标题",
      visible: false,
    });
    // 组件传递过来的
    function closeFun(data: boolean) {
      state.visible = data;
    }
    return {
      ...toRefs(state),
      closeFun,
    };
  },
});
</script>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/318528
推荐阅读
相关标签
  

闽ICP备14008679号