自定义指令(vue3)
不使用ts的时候去掉类型就好了
export default {
install(app: any) {
app.directive('focus', {
mounted(el: HTMLElement, bindings: any, vnode: any, preVnode: any) {
console.log(bindings);
el.focus();
}
});
app.directive('blur', {
mounted(el: HTMLElement, bindings: any, vnode: any, preVnode: any) {
console.log("blur mounted");
console.log(el);
el.blur();
}
});
}
}
main
import directive from './lib/directive'
createApp(App).use(directive)
使用
v-focus="'red'"
<input type="text" name="" id="" v-focus="'red'" v-model="from.password">