vue.js - TypeError: this.$refs.cropper.getCroppedCanvas 不是函数
问题描述
我想从图片网址裁剪、旋转照片。我将图像从 url 转换为 base64 字符串。图像显示在组件上。但是当我尝试裁剪图像时出现 TypeError: this.$refs.cropper.getCroppedCanvas is not a function。我通过 https://www.npmjs.com/package/vue-cropperjs 的npm install --save vue-cropperjs安装了它。
我已将其导入以下本地组件:
<tamplate>
<VueCropper ref="cropper" :src="imgSrc" alt="Source Image" :modal='true'>
</VueCropper>
</template>
<script lang="js">
import VueCropper from 'vue-cropperjs';
import 'cropperjs/dist/cropper.css';
export default Vue.extend({
components: { VueCropper}
setImage(path) {
var that = this;
function toDataURL(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onload = function () {
var reader = new FileReader();
reader.onloadend = function () {
callback(reader.result);
}
reader.readAsDataURL(xhr.response);
};
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.send();
}
toDataURL(path, function (dataUrl) {
that.imgSrc = dataUrl;
})
},
cropImage() {
// get image data for post processing, e.g. upload or setting image src
this.cropImg = this.$refs.cropper.getCroppedCanvas().toDataURL();
},
rotate() {
// guess what this does :)
this.$refs.cropper.rotate(90);
},
});
</script>
解决方案
推荐阅读
- python - discord.py 机器人脚本对 list.pop() 函数没有反应。如何解决这个问题?
- javascript - Python web 抓取请求和漂亮的汤被需要 javascript 阻止
- python - Python类型:连接序列
- http - 如何知道给定请求中http客户端使用的代理
- python - 如何根据输入参数多次运行 Python click 模块?
- javascript - 语法错误:错误:无法加载要扩展的配置“ckeditor5”。将 CKEditor 导入 Vuejs 时
- javascript - 在 setState 中 React Native 设置默认值
- python - 使用 C# BinaryReader 读取 python 二进制文件
- javascript - node.js 错误:连接 ECONNREFUSED;来自本地主机的响应
- javascript - 我应该存储标签中使用的文本吗?