use-vnode.vue 897 B

12345678910111213141516171819202122232425262728293031
  1. <template>
  2. <el-button plain @click="open">Common VNode</el-button>
  3. <el-button plain @click="open1">Dynamic props</el-button>
  4. </template>
  5. <script lang="ts" setup>
  6. import { h, ref } from 'vue'
  7. import { ElMessageBox, ElSwitch } from 'element-plus'
  8. const open = () => {
  9. ElMessageBox({
  10. title: 'Message',
  11. message: h('p', null, [h('span', null, 'Message can be '), h('i', { style: 'color: teal' }, 'VNode')]),
  12. })
  13. }
  14. const open1 = () => {
  15. const checked = ref<boolean | string | number>(false)
  16. ElMessageBox({
  17. title: 'Message',
  18. // Should pass a function if VNode contains dynamic props
  19. message: () =>
  20. h(ElSwitch, {
  21. modelValue: checked.value,
  22. 'onUpdate:modelValue': (val: boolean | string | number) => {
  23. checked.value = val
  24. },
  25. }),
  26. })
  27. }
  28. </script>