3
1

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 5 years have passed since last update.

Nuxt.js + TypeScriptでvue-awesome-swiperを使う

Last updated at Posted at 2019-10-06

Nuxtでスライダーを使いたかったので、良さげなライブラリを導入してみる。

環境

  • Windows 10 Pro
  • WSL Ubuntu
  • yarn -v -> 1.17.3
  • node -v -> v12.10.0
  • npm list nuxt -> nuxt@2.9.2
  • npm list vue -> vue@2.6.10

セットアップ

コマンドを打ってインストール

yarn add vue-awesome-swiper

plugins

plugins/vue-awesome-swiper.js
import Vue from 'vue' 
import VueAwesomeSwiper from 'vue-awesome-swiper' 

Vue.use(VueAwesomeSwiper)

nuxt config

nuxt.config.ts
import { Configuration } from '@nuxt/types'

const config: Configuration = {
  css: [
    'swiper/dist/css/swiper.css',
  ],

  plugins: [
    { src: '~plugins/vue-awesome-swiper', ssr: false },
  ],
}

export default config

動かしてみる

hoge.vue
<template>
  <div>
    <swiper :options="swiperOption">
      <swiper-slide></swiper-slide>
      <swiper-slide></swiper-slide>
      <swiper-slide></swiper-slide>

      <div class="swiper-button-prev" slot="button-prev"></div>
      <div class="swiper-button-next" slot="button-next"></div>
    </swiper>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'nuxt-property-decorator'

@Component
export default class Hogeeeeee extends Vue {
  swiperOption: object = {
    navigation: {
      nextEl: '.swiper-button-next',
      prevEl: '.swiper-button-prev'
    }
  }
}
</script>

オプションとかは、https://surmon-china.github.io/vue-awesome-swiper/ を参照してみてください。

参考

こちらの記事を参考にさせていただきました!
@IKEMAKI さん、ありがとうございました。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?