LoginSignup
0
0

More than 1 year has passed since last update.

Vue3.0 + Cropperjs

Last updated at Posted at 2021-11-25

はじめに

vueでcropperjsを使用する方法です

方法

1.プロジェクトの作成

vue create aaaaa

2.作成したプロジェクトに入り,cropperjsをインストール

cd aaaaa
npm install cropperjs

3.src/App.vueを以下のように変更

src/App.vue
<template>
  <img ref="cropImg" alt="Vue logo" src="./assets/logo.png">
  <HelloWorld msg="Welcome to Your Vue.js App"/>
</template>

<script>
import HelloWorld from './components/HelloWorld.vue'

import Cropper from 'cropperjs';
import "cropperjs/dist/cropper.css";

export default {
  name: 'App',
  components: {
    HelloWorld,
  },
  mounted() {
    this.cropper = new Cropper(this.$refs.cropImg, {
      background: false,
      modal: false,
      highlight: false,
      viewMode: 1
    });
  },
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

4.実行

npm run serve

5.結果

※クロップ後の画像が欲しい場合はthis.cropperが持っているのでそこから取得します

Screenshot from 2021-11-25 18-21-01.png

参考

vueとcropperjsによる映像クロップ: https://codesandbox.io/s/vue-cropperjs-video-u56xz?file=/src/main.js

環境

ubuntu20.04

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0