diff --git a/packages/my/examples/test/mini.project.json b/packages/my/examples/test/mini.project.json
index 308540c69..a78cf2256 100644
--- a/packages/my/examples/test/mini.project.json
+++ b/packages/my/examples/test/mini.project.json
@@ -1,7 +1,10 @@
{
+ "format": 2,
+ "compileOptions": {
+ "component2": true,
+ "enableNodeModuleBabelTransform": true
+ },
"scripts": {
"beforeCompile": "npm run beforeCompile"
- },
- "enableNodeModuleBabelTransform": true,
- "component2": true
-}
+ }
+}
\ No newline at end of file
diff --git a/packages/my/examples/test/pages/index/index.axml b/packages/my/examples/test/pages/index/index.axml
index 31eb304f8..d39edbcd3 100644
--- a/packages/my/examples/test/pages/index/index.axml
+++ b/packages/my/examples/test/pages/index/index.axml
@@ -1,3 +1,3 @@
-
+
\ No newline at end of file
diff --git a/packages/my/examples/test/pages/index/index.js b/packages/my/examples/test/pages/index/index.js
index c87722738..336d7c549 100644
--- a/packages/my/examples/test/pages/index/index.js
+++ b/packages/my/examples/test/pages/index/index.js
@@ -35,31 +35,34 @@ const data2 = [{
sold: 50
}];
Page({
- data: {// chartData: data1,
+ data: {
+ // chartData: data1,
},
-
onReady() {
this.setData({
chartData: data1
- }); // 模拟数据更新
-
+ });
+ // 模拟数据更新
setTimeout(() => {
this.setData({
chartData: data2
});
}, 2000);
},
-
+ onError(e) {
+ console.log(e);
+ },
onRenderChart(props) {
const {
data
} = props;
return _jsx(Chart, {
data: data
- }); // 如果不使用 jsx, 用下面代码效果也是一样的
+ });
+
+ // 如果不使用 jsx, 用下面代码效果也是一样的
// return createElement(Chart, {
// data: data,
// });
}
-
});
\ No newline at end of file
diff --git a/packages/my/examples/test/pages/index/index.jsx b/packages/my/examples/test/pages/index/index.jsx
index 08af9b18f..c676320f6 100644
--- a/packages/my/examples/test/pages/index/index.jsx
+++ b/packages/my/examples/test/pages/index/index.jsx
@@ -33,6 +33,9 @@ Page({
});
}, 2000);
},
+ onError(e){
+console.log(e)
+ },
onRenderChart(props) {
const { data } = props;
return ;
diff --git a/packages/my/src/index.tsx b/packages/my/src/index.tsx
index dcf69465c..d8926ba0e 100644
--- a/packages/my/src/index.tsx
+++ b/packages/my/src/index.tsx
@@ -35,27 +35,32 @@ Component({
return;
}
const { id } = this.data;
- const query = my.createSelectorQuery({ page: this.$page });
- query
- .select(`#${id}`)
- .boundingClientRect()
- .exec((res) => {
- // 获取画布实际宽高, 用props的宽高做失败兜底
- const { width, height } = res && res[0] ? res[0] : this.props;
- const pixelRatio = getPixelRatio();
- // 高清解决方案
- this.setData(
- {
- width: width * pixelRatio,
- height: height * pixelRatio,
- },
- () => {
- const myCtx = my.createCanvasContext(id);
- const context = F2Context(myCtx);
- this.canvasRender({ width, height, context, pixelRatio });
- }
- );
- });
+ const { onError } = this.props;
+ try {
+ const query = my.createSelectorQuery({ page: this.$page });
+ query
+ .select(`#${id}`)
+ .boundingClientRect()
+ .exec((res) => {
+ // 获取画布实际宽高, 用props的宽高做失败兜底
+ const { width, height } = res && res[0] ? res[0] : this.props;
+ const pixelRatio = getPixelRatio();
+ // 高清解决方案
+ this.setData(
+ {
+ width: width * pixelRatio,
+ height: height * pixelRatio,
+ },
+ () => {
+ const myCtx = my.createCanvasContext(id);
+ const context = F2Context(myCtx);
+ this.canvasRender({ width, height, context, pixelRatio });
+ }
+ );
+ });
+ } catch (error) {
+ onError && onError(error);
+ }
},
didUpdate() {
const { canvas, props } = this;