index.vue 1005 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <!-- 图表组件 -->
  2. <template>
  3. <view class="chart_content_item">
  4. <LEchart ref="chartRef"></LEchart>
  5. </view>
  6. </template>
  7. <script>
  8. import LEchart from "@/components/l-echart/l-echart.vue"
  9. import * as echarts from 'echarts'
  10. export default {
  11. components:{ LEchart },
  12. props:{
  13. option: {
  14. type: Object
  15. }
  16. },
  17. data(){
  18. return {
  19. chartRef:null
  20. }
  21. },
  22. mounted() {
  23. this.$nextTick(()=>{
  24. this.chartRef = this.$refs.chartRef;
  25. setTimeout(() => {
  26. if (!this.chartRef) return
  27. this.chartRef.init(echarts, chart => {
  28. chart.setOption(this.option)
  29. })
  30. }, 300)
  31. })
  32. },
  33. watch:{
  34. props:{
  35. handler:function(newVal, oldVal){
  36. if (this.chartRef) {
  37. this.chartRef.init(echarts, chart => {
  38. chart.setOption(newVal)
  39. })
  40. }
  41. },
  42. deep:true,
  43. immediate:true
  44. }
  45. }
  46. }
  47. </script>
  48. <style scoped lang="less">
  49. .chart_content_item {
  50. width: 100%;
  51. height: 100%;
  52. }
  53. </style>