vue实现自定义指令入门基础知识 |
您所在的位置:网站首页 › vue30自定义指令 › vue实现自定义指令入门基础知识 |
vue实现自定义指令入门基础知识_自定义基础教程 2020/03/23 18:37 • Web前端 全局的自定义指令Vue.directive(‘focus’, {inserted: function () {el.focus()} })在dom 中使用v-focus 使用这个自定义指令局部的自定义指令directives: {focus: {inserted: function (el) {el.focus()}} vue实现自定义指令入门基础知识全局的自定义指令 在dom 中使用v-focus 使用这个自定义指令 局部的自定义指令 directives: { focus: { inserted: function (el) { el.focus() } } }实例: 使用自定义指令跳转页面 directives: { gopage: { bind: (el, binding, vnode) => { // el 获取对应的作用元素的dom // vnode vue编译生成的虚拟节点 vnode.context 就是Vue对象也就是我们使用的this el.onclick = () => { vode.context.$router.path({ name: 'page' }) // 跳转到对应的页面 } } } }在项目中最好是将该指令单独写在一个文件中,在使用的地方直接引用。 ![]() |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |