formatter.vue 503 B

123456789101112131415161718192021222324
  1. <template>
  2. <!-- 将render函数变量写在temolate标签中 -->
  3. <render></render>
  4. </template>
  5. <script lang="ts" setup>
  6. import { ref, watch,h } from 'vue';
  7. // 定义父组件传过来的值
  8. const props = defineProps<{
  9. fn: any;
  10. }>();
  11. const render=ref();
  12. watch(
  13. props,
  14. async () => {
  15. render.value=h("div",null,props.fn)
  16. },
  17. {
  18. deep: true, //确认是否深入监听
  19. immediate: true, //确认是否以当前的初始值执行handler的函数
  20. }
  21. );
  22. </script>