Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.7k views
in Technique[技术] by (71.8m points)

如何通过自定义指令将 elementui el-tooltip 绑定到某个元素?

element 做的项目,动态表格需要添加行,并且需要做校验,但是默认下提示信息布局不好看(错误信息在输入框下面),所以我想通过指令实现,如果验证错误的控件,鼠标移动上去,就通过el-tooltip控件来提示错误,现在主要的问题是,如何在指令里面将 el-tooltip 和 输入框(验证错误的控件)绑定起来;

指令代码如下:


import Vue from 'vue'

export default{
  bind(el, binding, vnode) {

    const formItem = el.querySelector('.el-form-item__content')


    formItem.onmouseenter = (s) => {

      let current = el
      let formItemContent = current.children[0]
      if(formItemContent.children && formItemContent.children.length > 1) {
        let msg = formItemContent.children[1].innerText //错误信息

        // const ep = new Vue({
        //     el: document.createElement('span'),
        //     template: `<el-popover
        //     content="${msg}"
        //     popper-class="el-tooltip__popper" placement="top-start" :open-delay="10" trigger="hover"> <span slot="reference">${msg}</span>
        //     </el-popover>` })

        // formItem.appendChild(ep.$el)


      }


    }

  },
  unbind () {

    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...