vue-modern-cropper
v0.2.5
Published
Power-packed wrapper over cropperjs@next
Downloads
97
Readme
Vue Modern Cropper
Power-packed wrapper over cropperjs@next
Table of Contents
NOTE!!
vue-modern-cropper
uses cropperjs@next
(v2), which is not yet stable release, you can check it's documentation HERE
Feel free to submit PRs to add helper functions.
Usage
# Install it
pnpm add vue-modern-cropper
// Register it globally
import { ModernCropper } from 'vue-modern-cropper'
Vue.component(ModernCropper)
/* SomeComponent.vue */
// Or you could import it locally
import { ModernCropper } from 'vue-modern-cropper'
// Use InstanceType to infer the exposed props
const cropper = ref<InstanceType<typeof ModernCropper>>()
onMounted(() => {
// remember to await nextTick if you use Nuxt (Nuxt client component caveat)
await nextTick()
// Use onCropperMounted to execute hooks as soon as the cropper APIs is available
cropper.value!.onCropperMounted(({ cropper, image, canvas, selection, selections }) => {
selection.$toCanvas().then(canvas => console.log('cropped:', canvas.toDataURL()))
})
// Or access them directly through the ref, you need to make sure they are available though
if (cropper.value.cropperMounted)
cropper.value.cropper
})
...
<ModernCropper
ref="cropper"
class="w-80 h-40"
:src="imgSrc"
:pass-through="{
cropper: { constructOptions: undefined },
image: { attributes: { class: 'blur' } },
canvas: { attributes: { background: false } },
selection: { attributes: undefined },
selections: { attributes: undefined },
}"
/>
...
License
MIT @NamesMT