Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
When I use cloneNode to clone thrird part component like el-table in vue2

I want to make a feature about fixed thead in el-table. I plan to use Node.cloneNode() to clone the thead DOM and then fixed it. EveryThing goes well but something pazzle me.

I get the thead DOM and console it. It show me a width. Then I got a new clone DOM by using Node.cloneNode() and console it. It show me another width. It seems that cloneNode() not work well.

I have no idea and use setTimeout() to wrap Node.cloneNode(). It has a correct width equal to the first Time.

Brief code

handleHeaderDragend(newWidth, oldWidth, column, event) {
    this.initFixedHead()
},
initFixedHead() {
    this.$nextTick(() => {
        //el-table-fixed-header come out in the nextTick
        console.log(1, wrapper)
        console.log(2, wrapper.cloneNode(true))
        setTimeout(() => {
          console.log(3, wrapper.cloneNode(true))
        }, 0)
   })
}

total code

handleHeaderDragend(newWidth, oldWidth, column, event) {
  // console.log('haha')
  this.initFixedHead()
},
initFixedHead() {
  this.$nextTick(() => {
    const wrapper = this.$refs.table.$el.querySelector('.el-table__header-wrapper')
    const fixedWrapper = this.$refs.table.$el.querySelector('.el-table__fixed-header-wrapper')

    const headBox = document.querySelector('.sugar-table .el-table')
    const fixedHeadBox = document.querySelector('.sugar-table .el-table__fixed')

    if (fixedHeadBox.children.length > 0) {
      headBox.firstElementChild && headBox.removeChild(headBox.firstElementChild)
      fixedHeadBox.firstElementChild && fixedHeadBox.removeChild(fixedHeadBox.firstElementChild)
    }
    console.log(1, wrapper)
    console.log(2, wrapper.cloneNode(true))
    setTimeout(() => {
      console.log(3, wrapper.cloneNode(true))
      this.fixedHeadWidth = this.$refs.table.$el.querySelector('.el-table__fixed').getBoundingClientRect().width
      headBox.insertAdjacentElement('afterbegin', wrapper.cloneNode(true))
      fixedHeadBox.insertAdjacentElement('afterbegin', fixedWrapper.cloneNode(true))
        }, 0)
    })
}

console in chrome

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!