index.vue 775 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <div :id="chartId" style="width: 420px;height: 160px" />
  3. </template>
  4. <script>
  5. import echarts from 'echarts'
  6. export default {
  7. name: 'Hello',
  8. props: {
  9. chartId: {
  10. type: String,
  11. default: 'myChart'
  12. },
  13. option: {
  14. type: Object,
  15. default() {
  16. return {}
  17. }
  18. }
  19. },
  20. data() {
  21. return {
  22. msg: 'Welcome to Your Vue.js App'
  23. }
  24. },
  25. watch: {
  26. option(newValue, oldValue) {
  27. this.drawLine()
  28. }
  29. },
  30. mounted() {
  31. this.drawLine()
  32. },
  33. methods: {
  34. drawLine() {
  35. // 基于准备好的dom,初始化echarts实例
  36. const myChart = echarts.init(document.getElementById(this.chartId))
  37. // 绘制图表
  38. myChart.setOption(this.option)
  39. }
  40. }
  41. }
  42. </script>
  43. <style>
  44. </style>