withDirectives-options.uvue 878 字节
Newer Older
1
<script lang="uts">
2 3
  import { withDirectives } from 'vue'
  import type { DirectiveBinding } from 'vue'
4

5 6 7 8
  export default {
    data() {
      return {
        isMounted: false
9
      }
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
    },
    render() : VNode {
      const instance = this

      const customDirective = {
        mounted(el : UniElement, binding : DirectiveBinding, vnode : VNode, prevVNode : VNode | null) {
          console.log(el, binding, vnode, prevVNode)
          instance.$data['isMounted'] = true
        }
      } as Directive
      return h('view', { class: 'page' }, [
        withDirectives(h('text', 'Hello World'), [[customDirective]]),
        h('view', { class: 'mt-10 flex flex-row justify-between' }, [
          h('text', {}, `isMounted:`),
          h('text', { id: 'is-mounted' }, `${instance.$data['isMounted']}`),
        ])
26
      ])
27
    }
28
  }
29
</script>