vue3 + ts 使用el-dialog

弹窗组件

<template>
  <el-dialog v-model="dialogVisible" title="Tips" width="50%" :before-close="cancel">
    <div>
      <Form :formData="formData" :formDesc="formDesc" @submit="handleBaseSubmit" />
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="cancel">Cancel</el-button>
        <el-button @click="confirm" type="primary"> Confirm </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { TableData } from './tableData'
import Form from '../commonForm/Form.vue'
import { formDesc } from '../commonForm/FormData'
type Props = {
  dialogVisible: boolean
  currentRow: TableData
}
const props = defineProps<Props>()
console.log(props)
const emit = defineEmits(['update:dialogVisible'])
const formData = reactive<Record<string, any>>({
  name: '',
  region: '',
  time: '',
  delivery: false,
  type: [],
  resource: '',
  desc: ''
})
const cancel = () => {
  emit('update:dialogVisible', false)
}
const confirm = () => {
  emit('update:dialogVisible', false)
}
const handleBaseSubmit = (model: Record<string, any>) => {
  console.log(model) // 获取表单数据
}
</script>
<style scoped>
.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>

 父组件

<template>
  <addDialog v-model:dialogVisible="dialogVisible" v-if="dialogVisible" />
</template>
<script setup lang="ts">
import addDialog from './addDialog.vue'
let dialogVisible = ref<boolean>(false)
const viewRow = () => {
  dialogVisible.value = true
}
</script>
<style></style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值