欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 八卦 > uniapp开发安卓app--安卓低版本(4.4)不显示echarts图表问题解决思路

uniapp开发安卓app--安卓低版本(4.4)不显示echarts图表问题解决思路

2024/10/25 13:36:01 来源:https://blog.csdn.net/Z_B_L/article/details/141559905  浏览:    关键词:uniapp开发安卓app--安卓低版本(4.4)不显示echarts图表问题解决思路

在查阅了大量资料后,找到一个最有可能发生的问题——低版本安卓不兼容es6的语法,导致echarts不能正常被加载。

比如:

  1. 将箭头函数替换为传统的函数表达式。
  2. 将 ES6 的模块导出语法改为 module.exports
  3. 将 ES6 的类方法(如 datamethods 等)改为对象的方法。
  4. 将 let 和 const 改为 var
  5. 替换 ES6 的模板字符串为传统的字符串拼接。

es6转换成es5写法,我在这里列举一些最常见的:

导入

import * as echarts from '@/uni_modules/lime-echart/static/echarts.min'

转换成es5

var echarts = require('@/uni_modules/lime-echart/static/echarts.min');

uniapp中的data、onLaunch、onLoad、mounted、beforeDestroy等都要改成传统的function写法,不要使用箭头函数;并且export default 要改成 module.exports

module.exports = {data: function() {this.nowTimes();//这是一个函数},onLaunch: function() {this.nowTimes();},onLoad: function() {this.nowTimes();},mounted: function() {this.nowTimes();},beforeDestroy: function() {this.nowTimes();},
}

然后就是函数内部this的使用,调用函数:

methods:{nowTimes: function() {var self = this;self.timeNow(new Date());// setInterval(this.nowTimes,1000)self.timer = setInterval(() => {self.timeNow(new Date());}, 1000);},timeNow: function(timeStamp) {var year = new Date(timeStamp).getFullYear();var month = new Date(timeStamp).getMonth() + 1 < 10 ? "0" + (new Date(timeStamp).getMonth() + 1) : new Date(timeStamp).getMonth() + 1; var date=new Date(timeStamp).getDate() < 10 ? "0" + new Date(timeStamp).getDate() : new Date( timeStamp) .getDate(); var hh=new Date(timeStamp).getHours() < 10 ? "0" + new Date(timeStamp).getHours() : new Date( timeStamp) .getHours(); var mm=new Date(timeStamp).getMinutes() < 10 ? "0" + new Date(timeStamp).getMinutes() : new Date( timeStamp).getMinutes(); var ss=new Date(timeStamp).getSeconds() < 10 ? "0" + new Date(timeStamp).getSeconds() : new Date( timeStamp).getSeconds(); this.nowTime=hh + ":" + mm + ':' + ss;this.nowData=year + "." + month + "." + date; this.nowWeek="星期" + '日一二三四五六' .charAt(new Date().getDay()) }, 
}

生成echats 函数

init: function() {var self = this;// chart 图表实例不能存在data里self.$refs.chartRef.init(echarts).then(function(chart) {chart.setOption(self.option);});self.$refs.chartRefs.init(echarts).then(function(charts) {charts.setOption(self.options);});
},

就是用一个变量接收this,类似微信小程序的写法(不想吐槽ଲଇଉକ)

以上就是出现这种问题的一个解决思路,希望能对你有所帮助 (♡ര‿ര)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com