App.vue
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
<template> <div> <h2>Image Cropper Example with vue-img-cutter</h2> <!-- Trigger the cropping tool --> <ImgCutter ref="imgCutter" :isModal="true" :boxWidth="800" :boxHeight="400" :cutWidth="400" :cutHeight="300" :rate="'4:3'" :tool="true" @cutDown="handleCrop" > <!-- Custom slot for the open button --> <template #open> <button @click="openCutter">Choose Image</button> </template> </ImgCutter> <!-- Preview cropped image --> <div v-if="croppedImage" class="preview-section"> <h3>Cropped Image:</h3> <img :src="croppedImage.dataURL" alt="Cropped Image Preview" /> </div> </div> </template> <script> import ImgCutter from "vue-img-cutter"; export default { components: { ImgCutter }, data() { return { croppedImage: null, // To store cropped image data }; }, methods: { openCutter() { // Open the ImgCutter tool programmatically const image = { name: "sample.jpg", // Image name src: "https://via.placeholder.com/800x600", // Image source }; this.$refs.imgCutter.handleOpen(image); }, handleCrop(result) { // Handle the cropped image data this.croppedImage = result; console.log("Cropped Image Data:", result); }, }, }; </script> <style> .preview-section { margin-top: 20px; } .preview-section img { max-width: 100%; height: auto; } </style> |