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
- vue 中引用echarts 初始化init undefind問題(Cannot read property ‘init‘ of undefined)VueEchartsUndefined
- el-tree 報錯 TypeError: Cannot read property ‘setCheckedKeys‘ of undefined“ErrorUndefined
- 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
- Appium dmg 安裝:[TypeError: Cannot read property 'replace' of undefined]APPErrorUndefined
- vue 踩坑記錄 cannot read property xxx of undefinedVueUndefined
- vue init webpack報錯VueWeb
- Cannot set property 'innerHTML' of nullHTMLNull
- [Vue warn]: Error in render: "TypeError: Cannot read property 'matched' of undefined" found in <App> at src/App.vueVueErrorUndefinedAPP
- [Javascript] How javascript read the property?JavaScript
- Cannot set property ‘type‘ of null(vue)NullVue
- vue-router.esm.js?fe87:2210 TypeError: Cannot read property ‘$createElement‘ of undefinedVueJSErrorUndefined
- LoadRunner報錯vuser_init.c(18): Error: nca_connect_server: cannot communicateErrorServer
- 開啟託管server報錯:Cannot read from policy store. Reason is PolicyStore ErrorServerError
- go mod init報錯問題Go
- (排坑) Cannot create property 'key' on boolean 'true'Boolean
- BUG——AngularJS:Cannot set property ‘pic‘ of undefinedAngularJSUndefined
- Cannot set property ‘dataIndex‘ of undefined 大資料關係圖報錯,賦予的資料有重複,去重AIIndexUndefined大資料
- PHP報錯:Call to undefined function curl_init()PHPUndefinedFunction
- allowedOrigins cannot contain the gateway 報錯AIGateway
- 使用pillow開啟TIFF檔案報tempfile.tif: Cannot read TIFF header錯誤的解決方案Header
- gateway 報錯 allowedOrigins cannot contain the specialGatewayAI
- 【報錯】elasticsearch 報錯blocked by: [FORBIDDEN/12/index read-only / allow delete (api)]ElasticsearchBloCORBIndexdeleteAPI
- MySQL 報錯'Variable 'XXX' is a read only variable'MySql
- 完美解決呼叫“sudo rosdep init“命令時的報錯ROS
- tar (child): bzip2: Cannot exec: No such file or directory 報錯
- PHP報錯:?configure: error: Cannot find libmysqlclientPHPErrorIBMMySqlclient
- object dict cannot be used in await expression報錯解釋ObjectAIExpress
- pip安裝selenium報錯:Read timed out
- cannot read prpperty ‘start‘ of undefined(問題記錄)Undefined
- React報錯之Function components cannot have string refsReactFunction
- 解決String cannot be cast to java.util.List報錯ASTJava
- Python django報錯ImportError: cannot import name find_specPythonDjangoImportError