Skip to content

Commit 8108c40

Browse files
committed
添加首页轮播图
1 parent 4455356 commit 8108c40

File tree

5 files changed

+84
-9
lines changed

5 files changed

+84
-9
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"postcss-viewport-units": "^0.1.4",
1919
"postcss-write-svg": "^3.0.1",
2020
"vue": "^2.5.2",
21+
"vue-awesome-swiper": "^3.1.3",
2122
"vue-router": "^3.0.1",
2223
"vuejs-datepicker": "^0.9.29"
2324
},

src/App.vue

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export default {
1212
}
1313
</script>
1414
<style lang="scss">
15-
@import './style/reset';
1615
.router-fade-enter-active, .router-fade-leave-active {
1716
transition: opacity .3s;
1817
}

src/main.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import Vue from 'vue'
44
import App from './App'
55
import router from './router'
6+
import './style/reset.scss'
67

78
Vue.config.productionTip = false
89

src/page/home/Home.vue

+48-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55
<a class="msg-btn"></a>
66
</header>
77
<div class="container">
8-
<section class="slider"></section>
8+
<section class="slider">
9+
<swiper :options="swiperOption" ref="mySwiper" class="myswiper">
10+
<!-- slides -->
11+
<swiper-slide v-for="(item,index) in swiperList" :key="index">
12+
<img :src="item.imgUrl" alt="" class="swiper-img">
13+
</swiper-slide>
14+
<!-- Optional controls -->
15+
<div class="swiper-pagination" slot="pagination"></div>
16+
</swiper>
17+
</section>
918
<nav class="lesson-list">
1019
<router-link class="lesson-item" :to="{path: '/lesson', query: {lessonName: item.lessonName, id: item.id}}" v-for="(item,index) in lessonNav" :key="index">
1120
<img class="lesson-item-icon" :src="item.imgUrl" alt="">
@@ -20,11 +29,25 @@
2029
<script>
2130
import tabBox from '@/components/TabBox'
2231
import footBottom from '@/components/Footer'
32+
import 'swiper/dist/css/swiper.css'
33+
import '../../style/swiper.scss'
34+
import { swiper, swiperSlide } from 'vue-awesome-swiper'
35+
2336
export default {
2437
name: 'webHome',
2538
data () {
2639
return {
27-
msg: 'init',
40+
swiperList: [
41+
{
42+
imgUrl: require('../../assets/images/series_1.png')
43+
},
44+
{
45+
imgUrl: require('../../assets/images/series_2.png')
46+
},
47+
{
48+
imgUrl: require('../../assets/images/series_1.png')
49+
}
50+
],
2851
lessonNav: [
2952
{
3053
lessonName: '语文',
@@ -122,12 +145,33 @@ export default {
122145
view: '1265',
123146
price: 53.6
124147
}
125-
]
148+
],
149+
swiperOption: {
150+
pagination: {
151+
el: '.swiper-pagination',
152+
clickable: true,
153+
bulletClass: 'slide-bullet',
154+
bulletActiveClass: 'slide-bullet-active'
155+
},
156+
autoplay: true,
157+
loop: true
158+
}
126159
}
127160
},
128161
components: {
129162
tabBox,
130-
footBottom
163+
footBottom,
164+
swiper,
165+
swiperSlide
166+
},
167+
computed: {
168+
swiper () {
169+
return this.$refs.mySwiper.swiper
170+
}
171+
},
172+
mounted () {
173+
},
174+
methods: {
131175
}
132176
}
133177
</script>
@@ -171,10 +215,6 @@ export default {
171215
background-size: cover;
172216
}
173217
}
174-
.slider{
175-
height:268px;
176-
background-color:#d2d2d2;
177-
}
178218
.lesson-list{
179219
padding:8px 10px;
180220
display: flex;

src/style/swiper.scss

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
@import './variable.scss';
2+
.slider{
3+
height:268px;
4+
background-color:#d2d2d2;
5+
@at-root .myswiper{
6+
height: 100%;
7+
@at-root .swiper-img{
8+
width:100%;
9+
height:100%;
10+
}
11+
@at-root .slide-bullet {
12+
display: block;
13+
float:left;
14+
margin-left:11px;
15+
width:15px;
16+
height:15px;
17+
border:3px solid $green;
18+
border-radius: 50%;
19+
}
20+
@at-root .slide-bullet-active{
21+
background-color: $green;
22+
}
23+
}
24+
}
25+
26+
.swiper-container-horizontal>.swiper-pagination-bullets, .swiper-pagination-custom, .swiper-pagination-fraction{
27+
position: absolute;
28+
left: initial;
29+
right:33px;
30+
bottom:15px;
31+
width:80px;
32+
height:15px;
33+
overflow: hidden;
34+
}

0 commit comments

Comments
 (0)