we-plugin / we-cropper

微信小程序图片裁剪工具
https://we-plugin.github.io/we-cropper/#/
MIT License
2.16k stars 450 forks source link

给new WeCropper(cropperOpt,this ) 加入第二个参数 #150

Closed mannymu closed 4 years ago

mannymu commented 4 years ago

第二个参数,传入当前组件的 this , 方便在自定义组件中嵌套。 修改点: image

创建 画布的时候使用: image

close-issue-app[bot] commented 4 years ago

Issue tracker 只用于反馈 bug 和 feature request。在提问前请仔细阅读我们的文档,并推荐阅读《提问的智慧》:https://github.com/ruby-china/How-To-Ask-Questions-The-Smart-Way/blob/master/README-zh_CN.md

dlhandsome commented 4 years ago

感谢建议,这里本身是支持在自定义组件中使用的,文档中没有注明。

可以在构造器参数中自定义设置 canvas 容器的上下文:

new WeCropper({ // ... other options // 用于拖拽缩放的画布上下文 ctx: wx.createCanvasContext(id, this), // 用于生成图片的画布上下文 targetCtx: wx.createCanvasContext(targetId, this) })

可以参考 miniprogram-cropper 源码里面的用法 https://github.com/we-plugin/we-cropper/blob/master/packages/miniprogram-cropper/src/index.js#L28