withDirectives-options.uvue 875 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<script lang="uts">
import {withDirectives } from 'vue'
import type { DirectiveBinding } from 'vue'

export default {
  data(){
    return {
      isMounted: false
    }
  },
  // android 端暂不支持
  // render 写入 instance 参数编译报错 error: '$render' overrides nothing‌
  render(instance: ComponentPublicInstance):VNode {
    const customDirective = {
      mounted(el : UniElement, binding : DirectiveBinding, vnode : VNode, prevVNode: VNode | null) {
        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', {}, `${instance.$data['isMounted']}`),
      ])
    ])
  }
}
</script>