vue框架中的表单输入框不支持focus以及blur事件的解决方案

采用指令的方式来解决这个问题(此处的前端框架以mint-ui为例):

1.html引用: v-mtfocus


2.在实例中添加指令

directives: {
    'mtfocus' (el, binding, vnode) {
      let mtinput = el.querySelector('input')
      mtinput.onfocus = function () {
       ...//如果要对节点的数据进行更改,且更改要映射到页面上,则更改可在vnode.context上进行,这样,改完之后,改变就会映射到页面
      }
      mtinput.onblur = function () {
        ...//同上理
      }
    }

  }

猜你喜欢

转载自blog.csdn.net/weixin_42011096/article/details/80764182
今日推荐