vue3-core/playground/src/directive.vue

37 lines
863 B
Vue
Raw Normal View History

2023-12-03 18:36:01 +08:00
<script setup lang="ts">
import { ObjectDirective, FunctionDirective, ref } from '@vue/vapor'
2023-12-03 18:36:01 +08:00
const text = ref('created (overwrite by v-text), ')
2023-12-04 16:08:15 +08:00
const vDirective: ObjectDirective<HTMLDivElement, undefined> = {
created(node) {
if (!node.parentElement) {
node.textContent += 'created, '
node.style.color = 'red'
} else {
alert('!')
}
},
beforeMount(node) {
if (!node.parentElement) node.textContent += 'beforeMount, '
},
mounted(node) {
if (node.parentElement) node.textContent += 'mounted, '
}
2023-12-03 18:36:01 +08:00
}
const vDirectiveSimple: FunctionDirective<HTMLDivElement> = (node, binding) => {
console.log(node, binding)
}
const handleClick = () => {
text.value = 'change'
}
2023-12-03 18:36:01 +08:00
</script>
<template>
<div
v-directive:foo.bar="text"
v-text="text"
v-directive-simple="text"
@click="handleClick"
/>
2023-12-03 18:36:01 +08:00
</template>