1. 自定义指令
leezozz 12/30/2022 vue
# 自定义指令
directives 一个对象,用于注册对当前组件实例可用的指令
// 模板中:
<input v-edit-focus="editingTodo === item.label">
export default defineComponent({
name: 'Index',
// 在模板中启用 v-edit-focus
directives: {
editFocus: (el, binding) => {
binding.value && el.focus()
}
}
})
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13