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-focus` Vue.directive('focus', { // 当被绑定的元素插入到 DOM 中时…… inserted: function (el) { // 聚焦元素 el.focus(); } });
在组件中注册
export default { directives: { focus: { // 指令的定义 inserted: function (el) { el.focus(); } } } };
钩子函数
钩子函数参数
{foo: true, bar: true}
<template> <div> <input type="text" v-focus> <div v-test:msg.a.b="message"></div> </div> </template> <script> export default { data () { return { message: 'some text' }; }, directives: { focus: { // 指令的定义 inserted: function (el) { el.focus(); } }, test: { bind: function (el, binding, vnode) { var s = JSON.stringify; el.innerHTML = 'name: ' + s(binding.name) + '<br>' + 'value: ' + s(binding.value) + '<br>' + 'expression: ' + s(binding.expression) + '<br>' + 'argument: ' + s(binding.arg) + '<br>' + 'modifiers: ' + s(binding.modifiers) + '<br>' + 'vnode keys: ' + Object.keys(vnode).join(', '); } } } }; </script>
展示为
在大多数使用场景, 我们会在bind钩子里绑定一些事件, 比如在document上用addEventListener绑定, 在unbind里用removeEventListener解绑
The text was updated successfully, but these errors were encountered:
No branches or pull requests
自定义指令
在全局中注册
在组件中注册
钩子函数
钩子函数参数
{foo: true, bar: true}
展示为
The text was updated successfully, but these errors were encountered: