图片裁剪-cropperjs

通过new Cropper 构建裁剪

安装插件: cropperjs

npm install cropperjs --save

// html

  <el-upload
                                        v-model="ruleForm.image"
                                        class="avatar-uploader"
                                        action="#"
                                        :limit="1"
                                        drag
                                        :before-upload="beforeUpload"
                                        :show-file-list="false"
                                        accept="image/png,  image/jpg, image/jpeg"
                                        style="width: 100%; height: 100%; color: '#409EFF'"
                                      >
                                        <div class="gift_dialog_imgbox">
                                          <div
                                            v-if="fileSetImg.url"
                                            class="gift_dialog_img"
                                            :style="{                                                             backgroundImage:`url(${fileSetImg.url})` }"
                                          >
                                            <div class="gift_dialog_iconbox">
                                              <Icon
                                                @click.stop="handlePictureCardPreview"
                                                icon="svg-icon:vector"
                                                class="gift_dialog_icon"
                                              />
                                          <--    <Icon
                                                @click.stop="handleRemove"
                                                icon="svg-icon:delete"
                                                class="gift_dialog_icon ml-10px"
                                              />
                                           -->
                                            </div>
                                          </div>
                                          <el-icon v-else class="avatar-uploader-icon">
                                            <Plus />
                                          </el-icon>
                                        </div>
                                      </el-upload>


// script
import 'cropperjs/dist/cropper.css'
import Cropper from 'cropperjs'

const cropper = ref(null)
const cropperHeight = ref()
const cropperWidth = ref()
const showImgDialogVisible = ref(false)
const banSayVisibility = ref(false)
let fileSetImg = ref<any>({
  url: '',
  name: '',
  base64: null
})


const handlePictureCardPreview: UploadProps['onPreview'] = async (uploadFile) => {
  // createImageViewer({
  //   urlList: [fileImg.value.url]
  // })
  showImgDialogVisible.value = true
  cropper.value && cropper.value.destroy()
  nextTick(() => {
    if (imageRef.value) {
      cropper.value = new Cropper(imageRef.value, {
        // 宽高比
        aspectRatio: 4 / 3, //设置裁剪框为固定的宽高比
        viewMode: 1,
        // 预览
        preview: '.image-view',
        // cropBoxResizable: false,
        background: false,
        crop(event) {
          cropperHeight.value = parseInt(event.detail.height)
          cropperWidth.value = parseInt(event.detail.width)
        },
        cropend() {
          // cropper.value = null
        }
      })
    }
  })
}

<think>好的,我现在需要帮助用户解决关于vue-cropperjs官网的问题。首先,用户可能遇到了安装问题,之前询问过版本不匹配的错误,现在转向官网可能是为了寻找文档或正确版本信息。 首先,我需要确认vue-cropperjs的官网是否存在。根据之前的回复,用户可能已经被告知该包的版本问题,可能官网链接已经失效或变更。需要检查该包的官方资源在哪里。通常,npm包的官网可能在npm页面或者GitHub仓库。 接下来,搜索vue-cropperjs的npm页面,发现其最新版本是1.0.2,而用户之前遇到的错误是0.3.0不存在。这说明用户可能参考了过时的文档或教程,导致版本错误。需要引导用户到正确的资源,比如npm页面或GitHub仓库,而不是可能不存在的独立官网。 然后,考虑到用户可能需要文档或示例,需要提供GitHub仓库的链接,那里通常会有详细的使用说明。同时,可能用户需要替代方案,比如vue-cropper或其他类似库,尤其是如果他们使用的是Vue3,因为vue-cropperjs可能不支持。 此外,用户可能遇到访问官网的问题,比如链接失效或被墙,需要建议使用npm或GitHub作为主要信息来源,并推荐可靠的替代库,确保用户能找到正确的资源继续开发。 最后,确保回答结构清晰,分步骤引导用户,并提供备选方案,避免他们再次遇到类似问题。同时,保持语言简洁,避免技术术语过多,让用户容易理解。</think>--- ### **一、vue-cropperjs 官网信息** **vue-cropperjs** 是一个基于 Cropper.jsVue 图片裁剪组件,但 **官方并未提供独立官网**。以下是获取相关资源的可靠途径: --- ### **二、核心资源** #### 1. **GitHub 仓库** - **地址**: [https://github.com/Agontuk/vue-cropperjs](https://github.com/Agontuk/vue-cropperjs) - **内容**: - 安装与使用文档 - 示例代码 - 版本更新记录 - Issue 与讨论区 #### 2. **npm 官方页面** - **地址**: [https://www.npmjs.com/package/vue-cropperjs](https://www.npmjs.com/package/vue-cropperjs) - **内容**: - 最新版本号(当前为 `1.0.2`) - 安装命令 - 基础 API 说明 --- ### **三、替代访问方法** #### 1. **国内镜像加速** - **GitHub 镜像**: 使用 [GitHub Proxy](https://ghproxy.com/) 或 [FastGit](https://hub.fastgit.org/) ```bash # 示例:通过镜像克隆仓库 git clone https://hub.fastgit.org/Agontuk/vue-cropperjs.git ``` #### 2. **文档本地化** - 克隆仓库后,查看 `README.md` 文件获取本地文档。 --- ### **四、使用建议** #### 1. **版本兼容性** - **Vue2**: 使用 `vue-cropperjs@1.0.2` - **Vue3**: 需改用 [vue-picture-cropper](https://github.com/xyxiao001/vue-cropper) 或 [vue-advanced-cropper](https://github.com/Norserium/vue-advanced-cropper) #### 2. **基础代码示例** ```javascript // Vue2 中使用 vue-cropperjs import VueCropper from 'vue-cropperjs'; import 'cropperjs/dist/cropper.c
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值