Vue2函数式编程如何获取DOM

新手上路,请多包涵

为了动态生成echart图像,在render函数中生成了一个div,怎么把echart绑定在这个div上?

render (h, c) {
    const dom = h('div')
    const chart = ECharts.init(/* ? */)
}

?这里怎么绑定?

阅读 1.9k
2 个回答
新手上路,请多包涵

给div加个id吧,这样即能取到dom,以后如果用到多个图表,也不会重复

export default {
    // ...
    render(h) {
         return h('div', {
              attrs: {
                 id: 'echart'
              }
         })
   },
   mounted() {
      const options = {}
      const el = document.getElementById('echart')
      const chart = ECharts.init(/* ? */)
   }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题