鍍金池/ 問答/HTML/ vue中使用echarts自定義主題,報(bào)錯(cuò)ECharts is not Load

vue中使用echarts自定義主題,報(bào)錯(cuò)ECharts is not Loaded

vue中引入echarts和自定義的主題文件, 主題文件js報(bào)錯(cuò)ECharts is not Loaded。頁面上echarts的圖表是正確顯示的。

  import echarts from 'echarts/lib/echarts'
  import 'echarts/lib/chart/bar'
  import 'echarts/lib/component/tooltip'
  import 'echarts/lib/component/title'
  import '@/assets/echarts/mytheme' // 主題文件

  export default {
    name: 'user-chart',
    data () {
      return {
      }
    },
    mounted () {
      this.initChart()
    },
    methods: {
      initChart () {
        this.userChart = echarts.init(this.$refs['userChart'], 'mytheme')
        this.userChart.setOption({
          title: {
            text: 'ECharts 入門示例'
          },
          tooltip: {},
          xAxis: {
            data: ['襯衫', '羊毛衫', '雪紡衫', '褲子', '高跟鞋', '襪子']
          },
          yAxis: {},
          series: [{
            name: '銷量',
            type: 'bar',
            data: [5, 20, 36, 10, 10, 20]
          }]
        })
      }
    }
  }
回答
編輯回答
忠妾

找到了一種方法,把主題的json下載下來,放到j(luò)s文件中,比如theme.js

const theme = {//主題的json數(shù)據(jù)}
export default theme

然后在vue文件中

 import echarts from 'echarts/lib/echarts'
 import theme from 'themepath/theme'
 echarts.registerTheme('theme', theme) // 注冊(cè)主題
2017年7月13日 21:12
編輯回答
愿如初

把 js文件里的root.echarts 改成echarts;然后在該js文件內(nèi) import echarts from 'echarts'

2017年7月13日 17:55
編輯回答
毀憶

看下主題什么中的Echarts是不是為全局變量.
如果是的話.需要將echarts暴露出去.
不然無法引用

2018年4月26日 15:39