withDirectives-composition.uvue 823 字节
Newer Older
1 2 3 4 5 6 7
<script setup lang="ts">
  defineOptions({
    data() {
      return {
        isMounted: false
      }
    },
8 9 10
    render() : VNode {
      const instance = getCurrentInstance()!.proxy!
      
11
      const customDirective = {
12 13 14
        mounted(el : UniElement, binding : DirectiveBinding, vnode : VNode, prevVNode: VNode | null) {
          console.log(el, binding, vnode, prevVNode)
          instance.$data['isMounted'] = true
15 16 17 18 19
        }
      } as Directive
      return h('view', { class: 'page' }, [
        withDirectives(h('text', 'Hello World'), [[customDirective]]),
        h('view', { class: 'mt-10 flex flex-row justify-between' }, [
20
          h('text', {}, `isMounted:`),
21
          h('text', { id: 'is-mounted' }, `${instance.$data['isMounted']}`),
22 23 24 25 26
        ])
      ])
    }
  })
</script>