分析:created
调用location事件时获取dom
对象,是不行的,因为在created
钩子函数中是获取不到dom
的,我们可以使用mounted
钩子替换成created
钩子
<div id="main" style="width: 600px; height: 400px"></div>
复制
export default { mounted() { this.location(); }, methods: { location() { //创建 id为main的dom对象 let myChart = this.$echarts.init(document.querySelector("#main")); }, }, }; </script>
复制
在vue项目中简单使用Echarts&第一次使用时的各种报错与解决