当前位置:   article > 正文

vue框架二级路由echarts不显示问题解决_vue子组件echarts图不加载

vue子组件echarts图不加载

vue组件二级路由部分

  1. <template>
  2. <div>
  3. <ul class="routerbtn">
  4. <li>
  5. <router-link to="/Equipment/realdata1" @click.native="transformer"></router-link>
  6. </li>
  7. <li>
  8. <router-link to="/Equipment/realdata2" @click.native="GIS"></router-link>
  9. </li>
  10. <li>
  11. <router-link to="/Equipment/realdata3" @click.native="capacitor"></router-link>
  12. </li>
  13. <li>
  14. <router-link to="/Equipment/realdata4" @click.native="cabinet"></router-link>
  15. </li>
  16. </ul>
  17. <sbxx></sbxx>
  18. <video1></video1>
  19. <router-view></router-view>
  20. </div>
  21. </template>

echarts单组件

  1. <template>
  2. <div>
  3. <div id="chart3" style="width:100%;height:100%;" ref="echart"></div>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'echarts_L2',
  9. data() {
  10. return {
  11. }
  12. },
  13. mounted() {
  14. // this.echartss();
  15. let echarts = require('echarts');
  16. // var myChart = echarts.init(document.querySelector('#demo3'));
  17. var option = {
  18. tooltip: {
  19. trigger: 'item'
  20. },
  21. grid: {
  22. left: "-10%",
  23. right: "2%",
  24. width: "90%",
  25. bottom: "2%",
  26. top: "2%",
  27. containLabel: true
  28. },
  29. xAxis: {
  30. type: "value",
  31. splitLine: {
  32. show: false
  33. },
  34. axisLabel: {
  35. show: false
  36. },
  37. axisTick: {
  38. show: false
  39. },
  40. axisLine: {
  41. show: false
  42. }
  43. },
  44. yAxis: [{ //名称
  45. type: 'category',
  46. offset: -10,
  47. position: "left",
  48. axisLine: {
  49. show: false
  50. },
  51. inverse: false,
  52. axisTick: {
  53. show: false
  54. },
  55. axisLabel: {
  56. interval: 0,
  57. color: "#fff",
  58. align: "left",
  59. verticalAlign: "bottom",
  60. lineHeight: 32,
  61. fontSize: 16
  62. },
  63. data: ['母线运行电压', '微水实时数据', 'SF6泄露数值', 'SF6实时数据',]
  64. }, ],
  65. series: [{
  66. zlevel: 1,
  67. type: "bar",
  68. barGap: "10%",
  69. barWidth: "15px",
  70. animationDuration: 1500,
  71. align: "center",
  72. itemStyle: {
  73. normal: {
  74. barBorderRadius: 4
  75. }
  76. },
  77. data: [{
  78. value: 10,
  79. itemStyle: {
  80. color: "#11DCBEFF"
  81. }
  82. },
  83. {
  84. value: 80,
  85. itemStyle: {
  86. color: "#11DCBEFF"
  87. }
  88. },
  89. {
  90. value: 60,
  91. itemStyle: {
  92. color: "#11DCBEFF"
  93. }
  94. },
  95. {
  96. value: 40,
  97. itemStyle: {
  98. color: "#11DCBEFF"
  99. }
  100. },
  101. ],
  102. },
  103. {
  104. type: "bar",
  105. barWidth: 15,
  106. barGap: "-100%",
  107. margin: "0",
  108. tooltip: {
  109. show:false
  110. },
  111. data: [100, 100, 100, 100, 100],
  112. textStyle: {
  113. //图例文字的样式
  114. fontSize: 10,
  115. color: "#fff"
  116. },
  117. itemStyle: {
  118. normal: {
  119. color: "#FFF9F3",
  120. //width:"100%",
  121. fontSize: 10,
  122. barBorderRadius: 6
  123. },
  124. }
  125. }
  126. ],
  127. }
  128. // myChartLine.setOption(option);
  129. this.$nextTick(() => {
  130. var charts = echarts.init(this.$refs.echart)
  131. charts.clear()
  132. charts.resize()
  133. charts.setOption(option)
  134. })
  135. }
  136. }
  137. </script>

二级路由出现echarts不加载,由于初始化时dome还未加载。

所以会出现以下报错

            this.$nextTick(() => {
                    var charts = echarts.init(this.$refs.echart)
                    charts.clear()
                    charts.resize()
                    charts.setOption(option)
             })

this.$nextTick 将回调延迟到下次DOM更新循环之后执行。在修改数据之后立即使用它,然后等待DOM更新。所以问题就解决啦!(我也是找了很久,解决了之后分享给大家)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/124017?site
推荐阅读