app.json
"subPackages": [ { "root":"commonPackage", "pages":[] } ],
pages同级目录加commonPackage
分包中放入echarts组件信息
使用
xx.json
上面是分包组件,下面是加载前替换组件
"usingComponents": { "ec-canvas": "../../../commonPackage/components/echarts/ec-canvas" }, "componentPlaceholder": { "ec-canvas": "view" },
xx.js
// 引入
let echarts require('../../../commonPackage/components/echarts/echarts.js', utils => { echarts = utils }) let chart = null; // data: ec: {},
// func // 初始化图表 initChart(canvas, width, height, dpr) { chart = echarts.init(canvas, null, { width: width, height: height, devicePixelRatio: dpr // new }); canvas.setChart(chart); chart.setOption(this.data.option); return chart; }, // 获取数据后渲染 this.setData({ ec: { onInit: this.initChart } })
标签:canvas,..,chart,ec,commonPackage,分包,组件,echarts From: https://www.cnblogs.com/jqynr/p/16945314.html