当前位置:   article > 正文

new vue 动态创建子组件,插入DOM,销毁等操作_vue 动态子组件

vue 动态子组件

创建
前提:父级组件中,动态创建子组件,页面只做size响应,其他数据不响应

emptyChart:组件
props:传参
on:事件监听
  const initEmptyChart = new Vue({
        render(h) {
          return h(emptyChart, {
            props: {
              itemId: rowId + '-' + 'col' + colId,
              rowId: rowId,
            },
            on: {
              remove: (rowId, itemId) => {
                that.remove(rowId, itemId)
              },
              removeRow: rowId => {
                that.removeRow(rowId)
              }
            }
          })
        }
      })
      const initChartInstance = initEmptyChart.$mount()
      this.$refs[rowId + '-' + 'col' + colId] = initChartInstance.$children
      // 手动将子组件实例添加进父组件实例中
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

插入DOM

documen.body.appendChild(initChartInstance.$el)
  • 1

在父级中手动显式销毁实例

remove(itemref){
  this.$refs[itemref][0].$destroy()
}
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/222691
推荐阅读
相关标签
  

闽ICP备14008679号