use-vnode.vue 836 B

12345678910111213141516171819202122232425262728293031323334
  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, [
  12. h('span', null, 'Message can be '),
  13. h('i', { style: 'color: teal' }, 'VNode'),
  14. ]),
  15. })
  16. }
  17. const open1 = () => {
  18. const checked = ref<boolean | string | number>(false)
  19. ElMessageBox({
  20. title: 'Message',
  21. // Should pass a function if VNode contains dynamic props
  22. message: () =>
  23. h(ElSwitch, {
  24. modelValue: checked.value,
  25. 'onUpdate:modelValue': (val: boolean | string | number) => {
  26. checked.value = val
  27. },
  28. }),
  29. })
  30. }
  31. </script>