鍍金池/ 問答/HTML5  HTML/ vue按需引用echarts出錯

vue按需引用echarts出錯

項目中echarts插件, 用npm安裝好后,全局引用的方式可以實現(xiàn)效果圖,但是全局引入會將所有的echarts圖表打包,導致體積過大,所以我想按需引入,但是在按需引用的過程中,一直報如下錯誤,還請知道原因的大神們指導一下,告知一下為什么

<template>

<div class="container tob_system_mainpage">
    <div id="myChart" :style="{width: '300px', height: '300px'}"></div>
</div>

</template>
<style scoped>
</style>
<script>

// 引入基本模板
let echarts = require('echarts/lib/echarts')
// 引入柱狀圖組件
require('echarts/lib/chart/bar')
// 引入提示框和title組件
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')
export default {
    data() {
        return {

        }
    },
    created() {},
    mounted() {
        this.drawLine();
        this.drawPie();
    },
    methods: {
        drawLine() {
            // 基于準備好的dom,初始化echarts實例
            let myChart = echarts.init(document.getElementById('myChart'));
            // 繪制圖表
            myChart.setOption({
                title: { text: '在Vue中使用柱形圖echarts' },
                tooltip: {},
                xAxis: {
                    data: ["襯衫", "羊毛衫", "雪紡衫", "褲子", "高跟鞋", "襪子"]
                },
                yAxis: {},
                series: [{
                    name: '銷量',
                    type: 'bar',
                    data: [5, 20, 36, 10, 10, 20]
                }]
            });
        },
    },
}

</script>

前端頁面提示錯誤如下圖所示:

clipboard.png

求指教

回答
編輯回答
夏木

this.$echarts這個你哪來的

2018年5月25日 09:51