index.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <!--
  2. * @Author: daidai
  3. * @Date: 2022-02-28 16:29:08
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2022-04-25 15:45:57
  6. * @FilePath: \web-pc\src\pages\big-screen\components\echart\index.vue
  7. -->
  8. <template>
  9. <div :id="id" :class="className" :style="{ height: height, width: width }" />
  10. </template>
  11. <script>
  12. import tdTheme from './theme.json' // 引入默认主题
  13. export default {
  14. name: 'echart',
  15. props: {
  16. className: {
  17. type: String,
  18. default: 'chart'
  19. },
  20. id: {
  21. type: String,
  22. default: 'chart'
  23. },
  24. width: {
  25. type: String,
  26. default: '100%'
  27. },
  28. height: {
  29. type: String,
  30. default: '100%'
  31. },
  32. options: {
  33. type: Object,
  34. default: ()=>({})
  35. }
  36. },
  37. data () {
  38. return {
  39. chart: null
  40. }
  41. },
  42. watch: {
  43. options: {
  44. handler (options) {
  45. // 设置true清空echart缓存
  46. this.chart.setOption(options, true)
  47. },
  48. deep: true
  49. }
  50. },
  51. mounted () {
  52. // echarts.registerTheme('tdTheme', tdTheme); // 覆盖默认主题
  53. this.initChart();
  54. },
  55. beforeDestroy () {
  56. this.chart.dispose()
  57. this.chart = null
  58. },
  59. methods: {
  60. initChart () {
  61. // 初始化echart
  62. this.chart = echarts.init(this.$el, 'tdTheme')
  63. this.chart.setOption(this.options, true)
  64. }
  65. }
  66. }
  67. </script>
  68. <style>
  69. </style>