1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

vue-select-imageをvue+nuxtに導入

Last updated at Posted at 2021-08-18

手順

インストール

yarn add vue-select-image

プラグインの追加

plugins/imageselect.js
import Vue from 'vue'
import VueSelectImage from 'vue-select-image'
require('vue-select-image/dist/vue-select-image.css')
Vue.use(VueSelectImage)

nuxt.config.jsの編集:プラグインを追加します。

nuxt.config.js
  plugins: [
    {
      src: '@/plugins/imageselect',
      mode: 'client'
    }
  ],

コード:ちょっとエラーがconsoleに出てきたので、client-onlyで囲むことにより解決しています。

index.vue
<template>
    <client-only>
        <div class="container">
            <vue-select-image
                :data-images="dataImages"
                :is-multiple="false"
                :selected-images="initialSelected"
            />
        </div>
    </client-only>
</template>
 
<script>
 
export default {
  components: {},
  data() {
    return {
      dataImages:[{
        id: '1',
        src: 'https://unsplash.it/200?random',
        alt: 'Alt Image 1'
      }, {
        id: '2',
        src: 'https://unsplash.it/200?random',
        alt: 'Alt Image 2'
      }, {
        id: '2',
        src: 'https://unsplash.it/200?random',
        alt: 'Alt Image 2',
        disabled: true
      }],
      initialSelected: [],
    };
  }
}
</script>
 
<style>
.container {
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  font-size: 70px;
}
</style>

こんな感じで表示されます。

Screen Shot 2021-08-18 at 13.34.31.png

参考

ありがとうございました。

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?