系统相关
首页 > 系统相关> > 解决 vue3.0部署nginx后 echarts二次渲染问题

解决 vue3.0部署nginx后 echarts二次渲染问题

作者:互联网

本地情况正常 结果部署nginx服务器后发现echarts图表第二次查看时就出问题了

解决办法就是我们在重新创建的时候,移除之前创建的实例并且重新创建一个Echarts实例:

onMounted(()=>{

  // echarts.init(document.getElementById("userSex")).dispose()
  const userSexChart = echarts.init(document.getElementById("userSex"));
  userSexChart.setOption(userSex);
  //
  // echarts.init(document.getElementById("songStyle")).dispose()
  const songStyleChart = echarts.init(document.getElementById("songStyle"));
  songStyleChart.setOption(songStyle);
  //
  // echarts.init(document.getElementById("singerSex")).dispose()
  const singerSexChart = echarts.init(document.getElementById("singerSex"));
  singerSexChart.setOption(singerSex);
  //
  // echarts.init(document.getElementById("country")).dispose()
  const countryChart = echarts.init(document.getElementById("country"));
  countryChart.setOption(country);
})
onBeforeUnmount(()=>{
   document.getElementById("userSex").removeAttribute('_echarts_instance_')
   document.getElementById("songStyle").removeAttribute('_echarts_instance_')
   document.getElementById("singerSex").removeAttribute('_echarts_instance_')
   document.getElementById("country").removeAttribute('_echarts_instance_')
})

标签:const,init,nginx,getElementById,vue3.0,songStyle,document,echarts
来源: https://www.cnblogs.com/OfflineBoy/p/16298543.html