1.解决域名不能使用问题:https: / / cdn. jsdelivr . net
2.解决2.7.7以上的基础库不能显示问题,2.9.0基础库不在支持wx.createCanvasContext导致
1.1.https:
1.2.把json文件后缀改成js,export { }
1.3.
const json = require('../../../utils/半.js')
onLoad() {
const that = this
this.writerCtx = createHanziWriterContext({
id: 'hz-writer',
character: '半',
strokeAnimationSpeed: 5,
delayBetweenStrokes: 10,
page: this,
charDataLoader: function (char, onComplete) {
onComplete(json.data)
},
radicalColor: '#1abc9c',
});
this.writerCtx.loopCharacterAnimation();
},
2.1 安装hanzi-writer-miniprogram安装官网就行,小程序构建npm,打开/miniprogram_npm/hanzi-writer-miniprogram文件夹中的index.js文件
修改var RenderTarget = function()这里面的RenderTarget方法
function RenderTarget(view) {
_classCallCheck(this, RenderTarget);
this.view = view;
this.eventEmitter = new _EventEmitter2.default();
const query = this.view.createSelectorQuery()
query.select('#writer-canvas', view).fields({ node: true, size: true })
.exec((res) => {
this.canvas = res[0].node
const dpr = wx.getSystemInfoSync().pixelRatio
this.canvas.width = res[0].width * dpr
this.canvas.height = res[0].height * dpr
this.ctx = this.canvas.getContext('2d')
this.ctx.scale(dpr, dpr)
})
this.ctx = polyfillCanvasCtx(wx.createCanvasContext('writer-canvas', view));
this.canvas = this.view.selectComponent('#writer-canvas');
}
楼主好,按照你的修改报这个错误遇到过吗
果然可以,多谢楼主,可以使用。中文字库可以使用我的地址:
var getCharDataUrl = function getCharDataUrl(char) { return 'https://wxapi.db101.cn/v1/hz/search/' + encodeURIComponent(char); };
没用