真机上用SVG path方式创建Path2D报错,模拟器没问题,为什么?
const p0 = new Path2D('M0,17.9322971 C5.61532453,24.4437317 10.3525062,28.1893917 14.2115451,29.169277 C16.8867392,29.848561 20.1217384,24.1110756 28.904537,14.2758908 C30.9285487,12.0093548 33.9603697,9.32524387 38,6.22355807');
错误:
MiniProgramError
"illegal param to init BindingPath2D"
String
var pathStringToCanvas = function pathStringToCanvas(pathString) {
var pathParts = pathString.split(/(^|\s+)(?=[A-Z])/).filter(function (part) {
return part !== ' ';
});
var commands = [function (ctx) {
return ctx.beginPath();
}];
pathParts.forEach(function (part) {
var _part$split = part.split(/\s+/),
_part$split2 = _toArray(_part$split),
cmd = _part$split2[0],
rawParams = _part$split2.slice(1);
var params = rawParams.map(function (param) {
return parseFloat(param);
});
if (cmd === 'M') {
commands.push(function (ctx) {
return ctx.moveTo.apply(ctx, params);
});
} else if (cmd === 'L') {
commands.push(function (ctx) {
return ctx.lineTo.apply(ctx, params);
});
} else if (cmd === 'C') {
commands.push(function (ctx) {
return ctx.bezierCurveTo.apply(ctx, params);
});
} else if (cmd === 'Q') {
commands.push(function (ctx) {
return ctx.quadraticCurveTo.apply(ctx, params);
});
} else if (cmd === 'Z') {
// commands.push((ctx) => ctx.closePath());
}
});
return function (ctx) {
return commands.forEach(function (cmd) {
return cmd(ctx);
});
};
};
const p0 = pathStringToCanvas('M0,17.9322971 C5.61532453,24.4437317 10.3525062,28.1893917 14.2115451,29.169277 C16.8867392,29.848561 20.1217384,24.1110756 28.904537,14.2758908 C30.9285487,12.0093548 33.9603697,9.32524387 38,6.22355807');
试试
好吧,换了种方式暂时解决了;