Registry / web-framework / vue-image-crop-upload

vue-image-crop-upload

JSON →
library3.0.3jsnpmunverified

vue-image-crop-upload is a Vue component designed for client-side image cropping and uploading, currently stable at version 3.0.3. It provides a rich UI for users to select, crop, and then upload images to a specified server endpoint. The component prioritizes a desktop user experience and explicitly advises against mobile use due to its design. Key differentiators include its compatibility with Vue 3 (since v3.0.0), support for older browsers like IE10+, and extensive customization options for the cropping interface, such as disabling circular or square previews and image rotation. While a specific release cadence isn't published, major version bumps appear tied to Vue framework updates, indicating stability rather than rapid iteration. It integrates easily into Vue applications, handling image selection, client-side manipulation, and direct HTTP upload with configurable parameters and headers.

npm install vue-image-crop-upload
INSTALL
IMPORT
SIG · VUE-IMAGE-CROP-UPL
V
vue-image-crop-upload
web-frameworkjavascriptv3.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

VueImageCropUpload
import VueImageCropUpload from 'vue-image-crop-upload';
const VueImageCropUpload = require('vue-image-crop-upload');
Since version 3.0.0, the package is ESM-first and designed for Vue 3, making CommonJS `require` less suitable for modern projects.
Component Registration (Local)
import VueImageCropUpload from 'vue-image-crop-upload'; export default { components: { VueImageCropUpload }, // ... }
Standard local component registration within a Vue 3 component. The component is typically used directly in templates.
Component Registration (Global)
import VueImageCropUpload from 'vue-image-crop-upload'; createApp(App).component('vue-image-crop-upload', VueImageCropUpload).mount('#app');
Vue.component('vue-image-crop-upload', VueImageCropUpload);
For Vue 3 applications, global components are registered on the application instance, not a global Vue object like in Vue 2.

Demonstrates how to integrate `vue-image-crop-upload` into a Vue 3 application. It shows component registration, basic usage with `v-model` for visibility, setting custom `width`, `height`, upload `url`, `field` name, `params`, and `headers`. Event listeners for `crop-success`, `crop-upload-success`, and `crop-upload-fail` are included to handle the image cropping and upload lifecycle, with `process.env` placeholders for API keys.

import { createApp, ref } from 'vue'; import VueImageCropUpload from 'vue-image-crop-upload'; const app = createApp({ components: { 'vue-image-crop-upload': VueImageCropUpload }, setup() { const show = ref(false); const params = ref({ token: process.env.VUE_APP_UPLOAD_TOKEN ?? 'dummy_token', name: 'avatar' }); const headers = ref({ authorization: `Bearer ${process.env.VUE_APP_AUTH_KEY ?? ''}` }); const imgDataUrl = ref(''); const toggleShow = () => { show.value = !show.value; }; const cropSuccess = (imgDataUrlLocal: string, field: string) => { console.log('Cropping successful. Field:', field); imgDataUrl.value = imgDataUrlLocal; // Update the preview }; const cropUploadSuccess = (jsonData: any, field: string) => { console.log('Upload successful. JSON Data:', jsonData, 'Field:', field); alert('Upload success!'); show.value = false; // Close modal on success }; const cropUploadFail = (status: number, field: string) => { console.log('Upload failed. Status:', status, 'Field:', field); alert(`Upload failed with status: ${status}`); }; return { show, params, headers, imgDataUrl, toggleShow, cropSuccess, cropUploadSuccess, cropUploadFail }; }, template: ` <div id="app-container"> <h1>Vue Image Crop Upload Demo</h1> <img v-if="imgDataUrl" :src="imgDataUrl" alt="Cropped Image Preview" style="max-width: 200px; max-height: 200px; border: 1px solid #ccc; margin-bottom: 20px;" /> <button @click="toggleShow">Upload New Avatar</button> <vue-image-crop-upload v-model:show="show" :width="300" :height="300" url="/api/upload-avatar" <!-- Replace with your actual backend upload endpoint --> field="upload" img-format="png" :params="params" :headers="headers" @crop-success="cropSuccess" @crop-upload-success="cropUploadSuccess" @crop-upload-fail="cropUploadFail" ></vue-image-crop-upload> <p>This demo illustrates how to integrate and use the <code>vue-image-crop-upload</code> component in a Vue 3 application. It sets up basic visibility control, defines upload parameters and headers, and handles success and failure events. The <code>url</code> prop should point to a valid backend API endpoint capable of handling image uploads.</p> </div> ` }); app.mount('#app-container');
Debug
Known issues
breakingVersion 3.0.0 introduced full compatibility with Vue 3. This means projects built on Vue 2 will be incompatible and should use an older version (e.g., ^2.x.x) of the component.
fix
For Vue 2 projects, downgrade to a version compatible with Vue 2 (e.g., `npm install vue-image-crop-upload@^2`). For Vue 3 projects, ensure you are on v3.0.0 or higher.
affects: >=3.0.0
gotchaThe component is explicitly 'not recommended for use on the mobile side'. Developers should be aware of this limitation and implement alternative solutions or responsive adjustments for mobile users.
fix
Consider using alternative image cropping libraries optimized for mobile responsiveness or implement conditional rendering to hide/disable this component on mobile viewports.
affects: >=1.0.0
gotchaIf the `url` prop is not provided or is an empty string, the component will not perform an upload, leading to silent failure of the upload functionality.
fix
Always ensure the `url` prop is set to a valid backend endpoint for image processing and upload. Double-check its value and that the endpoint is reachable.
affects: >=1.0.0
Errors
Common errors & fixes
Failed to resolve component: vue-image-crop-upload
The component was not properly imported or registered in your Vue application.
fix
Ensure you have `import VueImageCropUpload from 'vue-image-crop-upload';` at the top of your component/main file and that it's listed in the `components` option (for local use) or globally registered with `app.component()` (for global use).
TypeError: Cannot read properties of undefined (reading 'length') in vue-image-crop-upload.umd.js
This often occurs when the component's internal methods expect certain props or data to be defined, but they are missing or incorrectly typed, possibly due to an invalid `imgFormat` or `imgBgc` value.
fix
Verify that `imgFormat` is 'jpg' or 'png' and `imgBgc` is a valid color string (e.g., '#fff') if `imgFormat` is 'jpg'. Check all props for correct types as specified in the documentation.
ERR_NAME_NOT_RESOLVED or 404 Not Found in console network tab for upload request
The `url` prop provided to the component points to an invalid or unreachable backend endpoint, or the path is incorrect.
fix
Double-check the `url` prop's value to ensure it's a correct and accessible API endpoint. Verify your backend server is running and configured to handle the POST request at that specific path.
Upgrade
Version history
3.0.3latest on npm
Audit
Dependencies
vuerequiredPeer dependency, the component is built for Vue 3.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
vue-image-crop-upload — npm install vue-image-crop-upload · libregistry