我有一个 Vue Advanced Cropper 的裁剪功能,如下所示:
crop() {
const { canvas } = this.$refs.cropper.getResult();
if (canvas) {
const form = new FormData();
canvas.toBlob(blob => {
form.append('files[]', blob);
// Perhaps you should add the setting appropriate file format here
}, 'image/jpeg');
this.formData = form;
}
},
我的 HTML:
Step 2: Crop images
{{ image.type }}
我已经包含了 Cropper 的导入:
import {Cropper} from 'vue-advanced-cropper'
package.json 中的版本:
"vue-advanced-cropper": "^2.8.1"
一切正常,直到我到达裁剪功能,其中显示以下内容:
未捕获类型错误:this.$refs.cropper.getResult不是函数
我的第一个想法是,它可能与循环多个图像有关,但是它也不适用于仅一个图像。我尝试将光盘中的部分组合起来并从这里上传到服务器: https://norserium.github.io/vue-advanced-cropper/guides/recipes.html#upload-image-to-a-server
--- 编辑 ---
我也有导出默认值,并且裁剪有效,只是没有得到结果:
export default {
components: {
Cropper,
},
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
aleksKamb 找到了正确的解决方案。应用索引后,它似乎正在工作。我将 v-for 编辑为:
然后我将裁剪函数编辑为:
crop(index) { const { canvas } = this.$refs.cropper[index].getResult(); if (canvas) { const form = new FormData(); canvas.toBlob(blob => { form.append('files[]', blob); // Perhaps you should add the setting appropriate file format here }, 'image/jpeg'); } },