Skip to content
This repository was archived by the owner on Jul 10, 2019. It is now read-only.

Commit 9fa6960

Browse files
authored
Merge pull request #19 from hisasann/feature/add-vue-awesome-swiper
feat: add vue-awesome-swiper
2 parents 880448b + 492a1a0 commit 9fa6960

File tree

6 files changed

+199
-2
lines changed

6 files changed

+199
-2
lines changed

nuxt.config.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ const config: NuxtConfiguration = {
121121
* Global CSS
122122
* 他の scss ファイルに依存しない scss はこちらに
123123
*/
124-
css: ['@/assets/styles/reset.scss', '@/assets/styles/main.scss'],
124+
css: [
125+
'@/assets/styles/reset.scss',
126+
'@/assets/styles/main.scss',
127+
'swiper/dist/css/swiper.css'
128+
],
125129

126130
/**
127131
* Plugins to load before mounting the App
@@ -132,7 +136,8 @@ const config: NuxtConfiguration = {
132136
'@/plugins/libraries/axios.ts',
133137
'@/plugins/libraries/vue-lazyload.ts',
134138
'@/plugins/locale/i18n.ts',
135-
{ src: '@/plugins/libraries/vue-carousel.ts', ssr: false }
139+
{ src: '@/plugins/libraries/vue-carousel.ts', ssr: false },
140+
{ src: '@/plugins/libraries/vue-awesome-swiper', mode: 'client' }
136141
],
137142

138143
/*

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
"@nuxtjs/axios": "^5.5.3",
5252
"@nuxtjs/pwa": "^3.0.0-beta.14",
5353
"@nuxtjs/sentry": "^3.0.0",
54+
"@types/shortid": "^0.0.29",
55+
"@types/swiper": "^4.4.3",
5456
"@types/webpack": "^4.4.32",
5557
"@ungap/url-search-params": "^0.1.2",
5658
"animejs": "^3.0.1",
@@ -63,8 +65,11 @@
6365
"nuxt-client-init-module": "^0.1.4",
6466
"nuxt-env": "^0.1.0",
6567
"nuxt-property-decorator": "^2.1.3",
68+
"shortid": "^2.2.14",
6669
"throttle-debounce": "^2.1.0",
6770
"ts-node": "^8.2.0",
71+
"vee-validate": "^2.2.9",
72+
"vue-awesome-swiper": "^3.1.3",
6873
"vue-carousel": "^0.18.0",
6974
"vue-i18n": "^8.11.2",
7075
"vue-lazyload": "^1.2.6"

src/pages/example/index.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ section
5757
nuxt-link(to='/example/routing-validate/false') routing-validate - validate is not true
5858
p
5959
nuxt-link(to='/example/v-scroll') v-scroll
60+
p
61+
nuxt-link(to='/example/vue-awesome-swiper') vue-awesome-swiper
6062
</template>
6163

6264
<script lang="ts">
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<template lang="pug">
2+
div
3+
div(v-swiper:swiper="swiperOption")
4+
.swiper-wrapper
5+
.swiper-slide(v-for="banner in banners")
6+
img(:src="banner")
7+
ul.swiper-pagination.swiper-pagination-bullets(:data-component-id="componentId" ref="pagination")
8+
.swiper-button-next(slot="button-next")
9+
.swiper-button-prev(slot="button-prev")
10+
11+
span(@click="prev", slot="button-prev")
12+
span(@click="next", slot="button-next")
13+
14+
div.space
15+
16+
p activeIndex: {{activeIndex}}
17+
</template>
18+
19+
<script lang="ts">
20+
import { Component, Vue } from 'nuxt-property-decorator'
21+
import shortid from 'shortid'
22+
import Swiper from 'swiper'
23+
// @ts-ignore
24+
import LemonSourSmallImage from '@/assets/images/lemon-sour.small.jpg'
25+
26+
@Component
27+
export default class VueAwesomeSwiper extends Vue {
28+
public banners: string[] = [
29+
LemonSourSmallImage,
30+
LemonSourSmallImage,
31+
LemonSourSmallImage,
32+
require('@/assets/images/lemon-sour.small.jpg'),
33+
require('@/assets/images/lemon-sour.small.jpg'),
34+
require('@/assets/images/lemon-sour.small.jpg')
35+
]
36+
37+
public activeIndex: number = 0
38+
39+
/** コンポーネントのID */
40+
public componentId: string = shortid.generate()
41+
42+
/** Swiperの設定 */
43+
public swiperOption = {}
44+
45+
/** Swiperのインスタンス */
46+
private swiper: Swiper
47+
48+
/** ライフサイクル */
49+
public beforeMount(): void {
50+
// ページマウント直前のcomponentIdを使ってカルーセルを設定
51+
this.swiperOption = {
52+
// loop: true,
53+
slidesPerView: 3,
54+
spaceBetween: 30,
55+
slidesPerGroup: 3,
56+
pagination: {
57+
el: `.swiper-pagination-bullets[data-component-id="${
58+
this.componentId
59+
}"]`,
60+
clickable: true,
61+
bulletElement: 'li'
62+
},
63+
navigation: {
64+
nextEl: '.swiper-button-next',
65+
prevEl: '.swiper-button-prev'
66+
}
67+
} as Swiper['params']
68+
}
69+
70+
public next(e) {
71+
console.log('next', this.swiper.activeIndex)
72+
this.swiper.slideNext(500)
73+
this.activeIndex = this.swiper.activeIndex
74+
}
75+
76+
public prev(e) {
77+
console.log('prev', this.swiper.activeIndex)
78+
this.swiper.slidePrev(500)
79+
this.activeIndex = this.swiper.activeIndex
80+
}
81+
82+
public mounted() {
83+
console.log('this is current swiper instance object', this.swiper)
84+
// this.swiper.slideTo(2, 1000, false)
85+
}
86+
87+
public head() {
88+
return {
89+
title: 'vue-awesome-swiper'
90+
}
91+
}
92+
}
93+
</script>
94+
95+
<style lang="scss" scoped>
96+
.swiper-container {
97+
margin-bottom: 10px;
98+
.swiper-wrapper {
99+
height: 300px;
100+
width: 100%;
101+
.swiper-slide {
102+
text-align: center;
103+
font-size: 38px;
104+
font-weight: 700;
105+
background-color: #eee;
106+
display: flex;
107+
justify-content: center;
108+
align-items: center;
109+
}
110+
.swiper-pagination {
111+
> .swiper-pagination-bullet {
112+
background-color: red;
113+
}
114+
}
115+
}
116+
}
117+
118+
.space {
119+
margin: 5px 0 5px 0;
120+
}
121+
</style>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @file vue-awesome-swiperをグローバルに登録する
3+
* @see https://github.com/surmon-china/vue-awesome-swiper/tree/master/examples/nuxt-ssr-example
4+
*/
5+
6+
import Vue from 'vue'
7+
import VueAwesomeSwiper from 'vue-awesome-swiper/dist/ssr'
8+
9+
Vue.use(VueAwesomeSwiper)

yarn.lock

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,6 +2256,11 @@
22562256
"@types/express-serve-static-core" "*"
22572257
"@types/mime" "*"
22582258

2259+
"@types/shortid@^0.0.29":
2260+
version "0.0.29"
2261+
resolved "https://registry.yarnpkg.com/@types/shortid/-/shortid-0.0.29.tgz#8093ee0416a6e2bf2aa6338109114b3fbffa0e9b"
2262+
integrity sha1-gJPuBBam4r8qpjOBCRFLP7/6Dps=
2263+
22592264
"@types/stack-utils@^1.0.1":
22602265
version "1.0.1"
22612266
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
@@ -2279,6 +2284,11 @@
22792284
resolved "https://registry.yarnpkg.com/@types/strip-json-comments/-/strip-json-comments-0.0.30.tgz#9aa30c04db212a9a0649d6ae6fd50accc40748a1"
22802285
integrity sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==
22812286

2287+
"@types/swiper@^4.4.3":
2288+
version "4.4.3"
2289+
resolved "https://registry.yarnpkg.com/@types/swiper/-/swiper-4.4.3.tgz#8f02e14b77ed51da563fb7cf669b7beb6d397451"
2290+
integrity sha512-z4RRt3/4ERHizeU8qIKmUsUpmoXFeEAJu0WLBZtjoVczaCnNL0KYQX0aBFZNhEu3bSNlMfWbZSHrg5gqAIucNA==
2291+
22822292
"@types/tapable@*":
22832293
version "1.0.4"
22842294
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.4.tgz#b4ffc7dc97b498c969b360a41eee247f82616370"
@@ -5183,6 +5193,13 @@ dom-walk@^0.1.0:
51835193
resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.1.tgz#672226dc74c8f799ad35307df936aba11acd6018"
51845194
integrity sha1-ZyIm3HTI95mtNTB9+TaroRrNYBg=
51855195

5196+
dom7@^2.1.3:
5197+
version "2.1.3"
5198+
resolved "https://registry.yarnpkg.com/dom7/-/dom7-2.1.3.tgz#a736f9c3bfbc4ca039a81cd095f97d1d7f3de19c"
5199+
integrity sha512-QTxHHDox+M6ZFz1zHPAHZKI3JOHY5iY4i9BK2uctlggxKQwRhO3q3HHFq1BKsT25Bm/ySSj70K6Wk/G4bs9rMQ==
5200+
dependencies:
5201+
ssr-window "^1.0.1"
5202+
51865203
domain-browser@^1.1.1:
51875204
version "1.2.0"
51885205
resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.2.0.tgz#3d31f50191a6749dd1375a7f522e823d42e54eda"
@@ -8934,6 +8951,11 @@ nan@^2.12.1, nan@^2.13.2:
89348951
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c"
89358952
integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==
89368953

8954+
nanoid@^2.0.0:
8955+
version "2.0.3"
8956+
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-2.0.3.tgz#dde999e173bc9d7bd2ee2746b89909ade98e075e"
8957+
integrity sha512-NbaoqdhIYmY6FXDRB4eYtDVC9Z9eCbn8TyaiC16LNKtpPv/aqa0tOPD8y6gNE4yUNnaZ7LLhYtXOev/6+cBtfw==
8958+
89378959
nanomatch@^1.2.9:
89388960
version "1.2.13"
89398961
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
@@ -11993,6 +12015,13 @@ shellwords@^0.1.1:
1199312015
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"
1199412016
integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==
1199512017

12018+
shortid@^2.2.14:
12019+
version "2.2.14"
12020+
resolved "https://registry.yarnpkg.com/shortid/-/shortid-2.2.14.tgz#80db6aafcbc3e3a46850b3c88d39e051b84c8d18"
12021+
integrity sha512-4UnZgr9gDdA1kaKj/38IiudfC3KHKhDc1zi/HSxd9FQDR0VLwH3/y79tZJLsVYPsJgIjeHjqIWaWVRJUj9qZOQ==
12022+
dependencies:
12023+
nanoid "^2.0.0"
12024+
1199612025
sigmund@^1.0.1:
1199712026
version "1.0.1"
1199812027
resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590"
@@ -12211,6 +12240,11 @@ sshpk@^1.7.0:
1221112240
safer-buffer "^2.0.2"
1221212241
tweetnacl "~0.14.0"
1221312242

12243+
ssr-window@^1.0.1:
12244+
version "1.0.1"
12245+
resolved "https://registry.yarnpkg.com/ssr-window/-/ssr-window-1.0.1.tgz#30752a6a4666e7767f0b7e6aa6fc2fdbd0d9b369"
12246+
integrity sha512-dgFqB+f00LJTEgb6UXhx0h+SrG50LJvti2yMKMqAgzfUmUXZrLSv2fjULF7AWGwK25EXu8+smLR3jYsJQChPsg==
12247+
1221412248
ssri@^6.0.1:
1221512249
version "6.0.1"
1221612250
resolved "https://registry.yarnpkg.com/ssri/-/ssri-6.0.1.tgz#2a3c41b28dd45b62b63676ecb74001265ae9edd8"
@@ -12539,6 +12573,14 @@ svgo@^1.0.0:
1253912573
unquote "~1.1.1"
1254012574
util.promisify "~1.0.0"
1254112575

12576+
swiper@^4.0.7:
12577+
version "4.5.0"
12578+
resolved "https://registry.yarnpkg.com/swiper/-/swiper-4.5.0.tgz#4d870bec4f5abe2fb259325849dd2641c9243c0d"
12579+
integrity sha512-jRCd/CGet9kaHwthHdd/sL/YU8CI157PWLyItnIcn/o/jP4haVky3zTF6f9F3JDpmQIw7jdWihISiYx0/oTHsg==
12580+
dependencies:
12581+
dom7 "^2.1.3"
12582+
ssr-window "^1.0.1"
12583+
1254212584
symbol-observable@^1.0.4:
1254312585
version "1.2.0"
1254412586
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804"
@@ -13280,6 +13322,11 @@ vary@~1.1.2:
1328013322
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
1328113323
integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=
1328213324

13325+
vee-validate@^2.2.9:
13326+
version "2.2.9"
13327+
resolved "https://registry.yarnpkg.com/vee-validate/-/vee-validate-2.2.9.tgz#4d4be9464acb00556cbc5c360f41b7bfd180412f"
13328+
integrity sha512-+nfg8dwH3rDOg8Y9sZ1TCvFFWXecRxG2L6sZelQECKrqLVjX4/UuFoyezhfPGMTfI6Lx66ygERgeRdOw4S3r4g==
13329+
1328313330
vendors@^1.0.0:
1328413331
version "1.0.3"
1328513332
resolved "https://registry.yarnpkg.com/vendors/-/vendors-1.0.3.tgz#a6467781abd366217c050f8202e7e50cc9eef8c0"
@@ -13306,6 +13353,14 @@ void-elements@^2.0.1:
1330613353
resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec"
1330713354
integrity sha1-wGavtYK7HLQSjWDqkjkulNXp2+w=
1330813355

13356+
vue-awesome-swiper@^3.1.3:
13357+
version "3.1.3"
13358+
resolved "https://registry.yarnpkg.com/vue-awesome-swiper/-/vue-awesome-swiper-3.1.3.tgz#05500b501ffb3fec9bf7eb9985bcf4ae8360ed9e"
13359+
integrity sha512-E7suzkyApO8vNZbgdEnjSmnpsmQZyRvSVXJ7sey3XYwKPOkLhH3+GnHroBw+5PZIQXvWBwdCeQsPG1xQ1r1Rhg==
13360+
dependencies:
13361+
object-assign "^4.1.1"
13362+
swiper "^4.0.7"
13363+
1330913364
vue-carousel@^0.18.0:
1331013365
version "0.18.0"
1331113366
resolved "https://registry.yarnpkg.com/vue-carousel/-/vue-carousel-0.18.0.tgz#478dfcad3abe2ee44c227020b6e60fb8484dc9f1"

0 commit comments

Comments
 (0)