Vue3.x的自定义指令
以input获取焦点为例
定义全局自定义指令
import { createApp } from 'vue'
import App from './App.vue'
const app = createApp(App)
app.directive('focus', {
mounted(el) {
el.focus()
}
})
app.mount('#app')
使用全局自定义指令
<input v-focus />
注册局部自定义指令
export default {
directives:{
focustt: {
mounted(el) {
// console.log(el.focus, 'elel')
el.focus()
}
}
},
}
使用局部自定义指令
<input v-focustt />
ok啦啦啦