mirror of https://github.com/vuejs/core.git
feat(compiler-vapor): functional custom directive support updated hooks (#58)
Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
This commit is contained in:
parent
42b913283b
commit
5e681b5945
|
|
@ -76,9 +76,9 @@ export function withDirectives<T extends Node>(
|
||||||
let [dir, source, arg, modifiers] = directive
|
let [dir, source, arg, modifiers] = directive
|
||||||
if (!dir) continue
|
if (!dir) continue
|
||||||
if (isFunction(dir)) {
|
if (isFunction(dir)) {
|
||||||
// TODO function directive
|
|
||||||
dir = {
|
dir = {
|
||||||
created: dir,
|
mounted: dir,
|
||||||
|
updated: dir,
|
||||||
} satisfies ObjectDirective
|
} satisfies ObjectDirective
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ObjectDirective } from '@vue/vapor'
|
import { ObjectDirective, FunctionDirective, ref } from '@vue/vapor'
|
||||||
|
|
||||||
const text = 'created (overwrite by v-text), '
|
const text = ref('created (overwrite by v-text), ')
|
||||||
const vDirective: ObjectDirective<HTMLDivElement, undefined> = {
|
const vDirective: ObjectDirective<HTMLDivElement, undefined> = {
|
||||||
created(node) {
|
created(node) {
|
||||||
if (!node.parentElement) {
|
if (!node.parentElement) {
|
||||||
|
|
@ -18,8 +18,19 @@ const vDirective: ObjectDirective<HTMLDivElement, undefined> = {
|
||||||
if (node.parentElement) node.textContent += 'mounted, '
|
if (node.parentElement) node.textContent += 'mounted, '
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const vDirectiveSimple: FunctionDirective<HTMLDivElement> = (node, binding) => {
|
||||||
|
console.log(node, binding)
|
||||||
|
}
|
||||||
|
const handleClick = () => {
|
||||||
|
text.value = 'change'
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div v-directive:foo.bar="text" v-text="text" />
|
<div
|
||||||
|
v-directive:foo.bar="text"
|
||||||
|
v-text="text"
|
||||||
|
v-directive-simple="text"
|
||||||
|
@click="handleClick"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue