LoginSignup
0
0

More than 1 year has passed since last update.

Vue3.0 + Vite + Cropperjs

Last updated at Posted at 2021-11-25

はじめに

前回の記事でVue3.0Cropperjsを使用する方法をまとめました。今回はビルド高速化の為にこれにViteを使った方法を記載します。

方法

1.パッケージの作成 + Viteのインストール + cropperjsのインストール

vue create aaaaa
cd aaaaa
npm init vite-app vue-todo-list
cd vue-todo-list
npm install
npm install cropperjs

2.vue-todo-list/src/App.vueを書き換える

vue-todo-list/src/App.vue
<template>
  <img ref="cropImg" alt="Vue logo" src="./assets/logo.png" />
  <HelloWorld msg="Hello Vue 3.0 + Vite + Cropperjs" />
</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>

3.実行

npm run dev

4.結果は以下のようになります

Screenshot from 2021-11-25 18-42-22.png

環境

ubuntu20.04

参考

Viteの使用方法: https://qiita.com/Toshiaki0315/items/1ab4e479007bb0f76f06

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