We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
除了 v-model、v-for等内置指令,Vue也允许注册自定义指令。主要有以下2种注册方式:
// 注册一个全局自定义指令 `v-focus` Vue.directive('focus', { // 当被绑定的元素插入到 DOM 中时…… inserted: function (el) { // 聚焦元素 el.focus() // 页面加载完成之后自动让输入框获取到焦点的小功能 } })
directives: { focus: { // 指令的定义 inserted: function (el) { el.focus() // 页面加载完成之后自动让输入框获取到焦点的小功能 } } }
自定义指令也像组件那样存在钩子函数:
...
The text was updated successfully, but these errors were encountered:
No branches or pull requests
自定义指令(允许用户注册指令扩展Vue功能)
除了 v-model、v-for等内置指令,Vue也允许注册自定义指令。主要有以下2种注册方式:
自定义指令也像组件那样存在钩子函数:
使用场景
1、权限校验 v-permission
2、复制指令 v-copy
3、长按 v-longpress
4、防抖节流 v-debounce
5、图片懒加载 v-lazy
6、拖拽 v-draggable
...
The text was updated successfully, but these errors were encountered: