Vue image cropping component example code

Vue image cropping component example code

Example:

tip: This component is based on vue-cropper secondary packaging

Install the plugin

npm install vue-cropper

yarn add vue-cropper

Write packaged components

<!-- Simple image cropping component--- Secondary packaging-->
<!-- More APIs https://github.com/xyxiao001/vue-cropper -->
<!-- Usage: Pass in the image ratio to display or hide. Method: Listen for the bottom button click --- add more props query documents yourself -->

<template>
  <div v-if="value" :value="value" @input="val => $emit('input', val)" class="conbox">
    <div class="info">
      <vueCropper
        ref="cropper"
        :img="img"
        :outputSize="outputSize"
        :outputType="outputType"
        :info="info"
        :canScale="canScale"
        :autoCrop="autoCrop"
        :fixed="fixed"
        :fixedNumber="fixedNumber"
        :full="full"
        :fixedBox="fixedBox"
        :canMove="canMove"
        :canMoveBox="canMoveBox"
        :original="original"
        :centerBox="centerBox"
        :infoTrue="infoTrue"
        :mode="mode"
      ></vueCropper>
    </div>
    <div class="btns">
      <div @click="clickCancelCut" class="cancel">Cancel</div>
      <img @click="clickRotate" src="../../assets/paradise/rotate.png" alt="" />
      <div @click="clickOk" class="okey">OK</div>
    </div>
  </div>
</template>

<script>
import { VueCropper } from 'vue-cropper';
export default {
  name: 'PictureCropping',
  components: { VueCropper },
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    //Crop the image address img: {
      type: String,
      default: '',
    },
    //The aspect ratio of the screenshot frame fixedNumber: {
      type: Array,
      default: () => {
        return [1, 1];
      },
    },
  },
  data() {
    return {
      // Basic configuration option for the cropping component
      : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :
  },
  computed: {},
  watch: {},
  //Life cycle - creation completed (access the current this instance)
  created() {},
  //Life cycle - Mounting completed (accessing DOM elements)
  mounted() {},
  methods: {
    clickCancelCut() {
      this.$emit('clickCancelCut', 'Click to cancel');
      this.$refs.cropper.stopCrop();
      this.$refs.cropper.clearCrop();
    },
    clickRotate() {
      this.$refs.cropper.rotateRight();
      this.$emit('clickRotate', 'Click to rotate');
    },
    clickOk() {
      //Output the trimmed base64
      this.$refs.cropper.getCropData(data => {
        this.$emit('clickOk', data);
        this.$refs.cropper.stopCrop();
        this.$refs.cropper.clearCrop();
      });
    },
  },
};
</script>
<style lang='less' scoped>
/* @import url(); Import css class*/
.conbox {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  box-sizing: border-box;
  height: 100vh;
  width: 100%;
  background-color: #000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  .info {
    width: auto;
    height: 800px;
    .vue-cropper {
      background-image: none;
      background-color: #000;
    }
  }
  .btns {
    padding: 0 20px;

    color: #fff;
    text-align: center;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 15px;
    img {
      width: 85px;
      height: 85px;
    }
    .cancel {
      background-color: #606465;
      padding: 15px 20px;
      width: 100px;
      border-radius: 10px;
    }
    .okey {
      background-color: #df6457;
      padding: 15px 20px;
      width: 100px;
      border-radius: 10px;
    }
  }
}
</style>

Summarize

This is the end of this article about the Vue image cropping component. For more relevant Vue image cropping component content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue project implements adding image cropping component
  • Detailed explanation of how to use vue-cropper, a Vue image cropping plugin
  • Vue realizes uploading after cropping pictures
  • Implementation of Vue image cropping and uploading component
  • Detailed explanation of implementing image cropping function in vue project
  • vue-image-crop is an example of a mobile image cropping component based on Vue
  • Vue-cropper The basic principles and ideas of picture cropping
  • Encapsulating Vue based on cropper.js to realize online image cropping component function
  • Cropper js implementation code of image cropping and uploading function based on Vue
  • Detailed explanation of the use of el-upload component and image cropping function component in ElementUI component of Vue project

<<:  Reasons and methods for Waiting for table metadata lock in MySQL

>>:  Example code and method of storing arrays in mysql

Recommend

What are your principles for designing indexes? How to avoid index failure?

Table of contents Primary key index Create indexe...

Detailed explanation of the solution to permission denied in Linux

Permission denied: The reason for this is: there ...

Implementation of formatting partitions and mounting in Centos7

Linux often encounters situations such as adding ...

How to implement logic reuse with Vue3 composition API

Composition API implements logic reuse steps: Ext...

How to implement html input drop-down menu

Copy code The code is as follows: <html> &l...

Optimization of MySQL thread_stack connection thread

MySQL can be connected not only through the netwo...

Sample code for installing ElasticSearch and Kibana under Docker

1. Introduction Elasticsearch is very popular now...

Nofollow makes the links in comments and messages really work

Comments and messages were originally a great way...

Common usage of hook in react

Table of contents 1. What is a hook? 2. Why does ...

Modify the jvm encoding problem when Tomcat is running

question: Recently, garbled data appeared when de...

Docker installation and deployment of Net Core implementation process analysis

1. Docker installation and settings #Install Cent...

jQuery plugin to implement minesweeper game (1)

This article shares the specific code of the firs...

Nginx configuration to achieve multiple server load balancing

Nginx load balancing server: IP: 192.168.0.4 (Ngi...

10 bad habits to avoid in Docker container applications

There is no doubt that containers have become an ...

Analysis of the method of setting up scheduled tasks in mysql

This article uses an example to describe how to s...