参考
学习Vue3 第二十七章(自定义指令directive)_vue3的directive_小满zs的博客-CSDN博客
使用演示
参数说明
<template>
<div v-move:a.b="{background:'red'}"></div>
</template>
<script setup lang='ts'>
import { Directive } from 'vue';
const vMove:Directive = {
mounted(...args:Array<any>){
console.log("onMounted")
console.log(args)
}
}
</script>
简单使用
<template>
<div v-move:a.b="{background:'red'}"> demo </div>
</template>
<script setup lang='ts'>
import { Directive, DirectiveBinding } from 'vue';
type Dir = {
background:string
}
const vMove:Directive = {
mounted(el:HTMLElement,dir:DirectiveBinding<Dir>){
console.log("onMounted")
console.log(dir.value.background)
el.style.background = dir.value.background
}
}
</script>