vue+echarts報錯Cannot read property ‘init‘ of underfined
在使用vue+echarts時報錯Cannot read property 'init' of underfined。
試了一下網路上的幾種方法發現沒有。
最後發現:
1.安裝echarts專案依賴時要先進入專案資料夾環境(-_-||)。
cd 專案檔案路徑
//例如 cd D:\project
npm install echarts --save
2.在import時要用單引號import echarts from 'echarts',不要用雙引號import echarts from "echarts"。
犯這種錯誤的我真傻Orz。
原步驟
https://www.cnblogs.com/rose-sharon/p/11755418.html
注意原文就犯了使用雙引號的錯誤
1. 安裝echarts專案依賴 npm install echarts --save 2. 在main.js中全域性引入 import echarts from "echarts"; Vue.prototype.$echarts = echarts;
<template> <div id="app"> <div id="main" style="width: 600px;height:400px;"></div> </div> </template>
js部分 script 程式碼
<script> export default { name: "app", methods: { drawChart() { // 基於準備好的dom,初始化echarts例項 let myChart = this.$echarts.init(document.getElementById("main")); // 指定圖表的配置項和資料 let option = { title: { text: "ECharts 入門示例" }, tooltip: {}, legend: { data: ["銷量"] }, xAxis: { data: ["襯衫", "羊毛衫", "雪紡衫", "褲子", "高跟鞋", "襪子"] }, yAxis: {}, series: [ { name: "銷量", type: "bar", data: [5, 20, 36, 10, 10, 20] } ] }; // 使用剛指定的配置項和資料顯示圖表。 myChart.setOption(option); } }, mounted() { this.drawChart(); } }; </script>
相關文章
- 前端報錯:cannot read property length of undefined前端Undefined
- 執行專案報錯Cannot read property 'styles' of undefinedUndefined
- el-tree 報錯 TypeError: Cannot read property ‘setCheckedKeys‘ of undefined“ErrorUndefined
- vue 中引用echarts 初始化init undefind問題(Cannot read property ‘init‘ of undefined)VueEchartsUndefined
- Cannot read property ‘aDataSort‘ of undefinedUndefined
- js提示Cannot read property ‘replace‘ of undefinedJSUndefined
- [譯] 避免那些可惡的 "cannot read property of undefined" 錯誤Undefined
- echarts:Uncaught TypeError: Cannot read property '0' of undefinedEchartsErrorUndefined
- AndroidStudio之自定義輸出包名報錯 Cannot set the value of read-only property 'outputFile' forAndroid
- vue 踩坑記錄 cannot read property xxx of undefinedVueUndefined
- vue-router.esm.js?fe87:2210 TypeError: Cannot read property ‘$createElement‘ of undefinedVueJSErrorUndefined
- [Vue warn]: Error in render: "TypeError: Cannot read property 'matched' of undefined" found in <App> at src/App.vueVueErrorUndefinedAPP
- zend_std_read_property
- [Javascript] How javascript read the property?JavaScript
- Cannot set property 'innerHTML' of nullHTMLNull
- vue init webpack報錯VueWeb
- Cannot set property ‘type‘ of null(vue)NullVue
- BUG——AngularJS:Cannot set property ‘pic‘ of undefinedAngularJSUndefined
- allowedOrigins cannot contain the gateway 報錯AIGateway
- go mod init報錯問題Go
- (排坑) Cannot create property 'key' on boolean 'true'Boolean
- gateway 報錯 allowedOrigins cannot contain the specialGatewayAI
- 使用pillow開啟TIFF檔案報tempfile.tif: Cannot read TIFF header錯誤的解決方案Header
- Cannot set property ‘dataIndex‘ of undefined 大資料關係圖報錯,賦予的資料有重複,去重AIIndexUndefined大資料
- 關閉tomcat報錯Cannot allocate memoryTomcat
- PHP報錯:Call to undefined function curl_init()PHPUndefinedFunction
- cannot read prpperty ‘start‘ of undefined(問題記錄)Undefined
- 【報錯】elasticsearch 報錯blocked by: [FORBIDDEN/12/index read-only / allow delete (api)]ElasticsearchBloCORBIndexdeleteAPI
- 執行 RabbitMQ時出錯 init terminating in do_boot ({cannot get bootfile,start_clean.boot})MQboot
- SQL2012報錯:cannot find one or more cpmponentsSQL
- object dict cannot be used in await expression報錯解釋ObjectAIExpress
- React報錯之Function components cannot have string refsReactFunction
- Vue init webpack xxxx project 報錯處理(connect ETIMEDOUT 192.30.253.112)VueWebProject
- 完美解決呼叫“sudo rosdep init“命令時的報錯ROS
- tar (child): bzip2: Cannot exec: No such file or directory 報錯
- 解決String cannot be cast to java.util.List報錯ASTJava
- 使用req.session.xxx時出現 Cannot set property ‘xxxx‘ of undefinedSessionUndefined
- imagick使用readImage報錯 Failed to read the file 或者沒有報錯內容的解決方法AI