vue3-core/playground/src/directive.vue

26 lines
588 B
Vue
Raw Normal View History

2023-12-03 18:36:01 +08:00
<script setup lang="ts">
2023-12-04 16:08:15 +08:00
import { ObjectDirective } from '@vue/vapor'
2023-12-03 18:36:01 +08:00
2023-12-04 16:08:15 +08:00
const text = 'created (overwrite by v-text), '
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
}
</script>
<template>
2023-12-04 16:08:15 +08:00
<div v-directive v-text="text" />
2023-12-03 18:36:01 +08:00
</template>