canvasToTempFilePath: fail canvas is empty 文档:canvas 文档说canvas 组件的唯一标识符,若指定了 type 则无需再指定该属性canvas-id 心得:所以把type属性去掉,保留canvas-id就可以获取到canvas 实例:<canvas style="width:300px;height:300px;border:1px solid red;" canvas-id="myCanvas"></canvas> 效果:可以获取到 代码: wx.canvasToTempFilePath( { x: 0, y: 0, width: 300, height: 300, destWidth: 100, destHeight: 100, canvasId: "myCanvas", success: res => { console.log("wx.canvasToTempFilePath-----res:", res); console.log(res.tempFilePath); }, fail: res => { console.log("wx.canvasToTempFilePath-----res:", res); } }, this );
canvasToTempFilePath: fail canvas is empty"data: { // 图标数据 doubleColumnCanvasData: { canvasId: 'doubleColumn', }, doubleColumnTitle: "近半年已获得认可", doubleColumnUnit: [{ color: "#94df87", title: "认可我的" }, { color: "#81bdfd", title: "认可币数" } ], // 图标数据 corpId: '', authCode: '', userId: '', // 悬赏点击按钮的参考值 tankk: 1, // 点击页面切换 qiehuan: 1, // 弹出框 qqt: '', // 轮播图配置 imgUrls: [], indicatorDots: true, autoplay: true, interval: 2000, duration: 1000, // 轮播图配置 user:'', ownBadge: 0, ownCoin: 0, ownPoint: 0, starUsers: [], stDatas: '', notices: [], sessionId:'' }, /** * 组件的方法列表 */ methods: { // 图表转图片 zhuantu(){ setTimeout(function () { wx.canvasToTempFilePath({ canvasId: 'doubleColumn', success: function (res) { var tempFilePath = res.tempFilePath; console.log(tempFilePath); }, fail: function (res) { console.log(res); } }); }, 500); }, onload直接调用的 [图片] 页面图表显示正常就转不了图片
2020-11-10