我想用 'cropperJS' 获得 50% 的图像。我创建了一个新的 Image() 并尝试创建新的 Cropper 以进一步获取画布。我收到错误“无法读取 null 的属性 'insertBefore'”,请帮我解决这个问题。或者告诉我如何在没有“cropperJS”的情况下获得 50% 的图像。提前致谢。
<template>
<v-layout
column
justify-center
align-center
>
<v-flex
xs12
sm8
md6
>
<vue-dropzone
ref="myVueDropzone"
id="dropzone"
:options="dropzoneOptions"
@vdropzone-success="vdropzoneSuccess"
>
</vue-dropzone>
<v-img
:src="imgUrl"
>
</v-img>
</v-flex>
</v-layout>
</template>
<script>
import Logo from '~/components/Logo.vue'
import VuetifyLogo from '~/components/VuetifyLogo.vue'
import vue2Dropzone from 'vue2-dropzone'
import 'vue2-dropzone/dist/vue2Dropzone.min.css'
import Cropper from 'cropperjs'
export default {
data: function () {
return {
imgUrl:'',
dropzoneOptions: {
url: 'https://httpbin.org/post',
thumbnailWidth: 150,
maxFilesize: 0.5,
headers: { "My-Awesome-Header": "header value" }
}
}
},
components: {
vueDropzone: vue2Dropzone
},
methods:{
vdropzoneSuccess(file, response){
this.imgUrl = file.dataURL
var image = new Image()
image.src = URL.createObjectURL(file)
console.log(image)
var cropper = new Cropper(image, {
aspectRatio: 16 / 9,
crop(event) {
console.log(event.detail.x)
console.log(event.detail.y)
console.log(event.detail.width)
console.log(event.detail.height)
},
})
console.log(cropper)
}
}
}
</script>