改变参数无效。。。轮播只能自己手动滑动才有效果。。
自己想了好久。没找到到底错在哪了。老师能不能帮忙看看
homeindex
<template>
<div class="home">
<router-view></router-view>
<div class="g-header-container">
<home-header></home-header>
</div>
<div class="g-middle-container">
<home-slider></home-slider>
</div>
<div class="g-backtop-container"></div>
</div>
</template>
<script>
import HomeHeader from './header'
import HomeSlider from './slider'
export default {
components:{
HomeHeader,
HomeSlider
},
props:{},
data(){
return {
}
},
watch:{},
computed:{},
methods:{},
created(){},
mounted(){}
}
</script>
<style lang="scss" scoped>
@import '../../assets/scss/mixins';
.home{
overflow: hidden;
width: 100%;
height: 100%;
background-color: $bgc-theme
}
</style>homeslider
<template>
<div class="slider-wrapper">
<my-slider
:direction="direction"
:loop='loop'
:interval='interval'
:pagination='pagination'
>
<swiper-slide
v-for="(item,index) in sliders"
:key="index"
>
<a :href="item.linkurl" class="slider-link">
<img :src="item.imgurl" alt="" class="slider-img">
</a>
</swiper-slide>
</my-slider>
</div>
</template>
<script>
import MySlider from '@/base/slider/index'
import {swiperSlide} from 'vue-awesome-swiper'
export default {
components:{
MySlider,
swiperSlide
},
props:{},
data(){
return {
direction: "",
loop: false,
interval: 0,
pagination: true,
sliders: [
{
'linkurl':'http://www.baidu.com',
'imgurl':require('./1.jpg')
},
{
'linkurl':'http://www.baidu.com',
'imgurl':require('./2.jpg')
},
{
'linkurl':'http://www.baidu.com',
'imgurl':require('./3.jpg')
},
{
'linkurl':'http://www.baidu.com',
'imgurl':require('./4.jpg')
}
]
}
},
watch:{},
computed:{},
methods:{},
created(){},
mounted(){}
}
</script>
<style lang="scss" scoped>
.slider-wrapper{
height: 183px;
}
.slider-link,
.slider-img{
width: 100%;
height: 100%;
}
</style>sliderindex
<template>
<swiper :options='swiperOption'>
<!-- 此为只正对本项目的写法 -->
<!-- <swiper-slide v-for="item in sliders">
<a href="">
<img src="" alt="">
</a>
</swiper-slide> -->
<slot></slot>
<!-- 分页器,决定是否需要分页 -->
<div class="swiper-pagination" v-if="pagination" slot="pagination"></div>
</swiper>
</template>
<script>
import {swiper} from 'vue-awesome-swiper';
import 'swiper/dist/css/swiper.css';
export default {
components:{
swiper,
},
props:{
direction: {
type: String,
default: 'horizontal',
validator(value) {
return [
'horizontal',
'vertical'
].indexOf(value) > -1;
}
},
interval: {
type: Number,
default: 3000,
validator(value) {
return value >= 0;
}
},
loop: {
type: Boolean,
default: true
},
pagination: {
type: Boolean,
default: true
}
},
data(){
return {
swiperOptions: {
watchOverflow: true,
direction: this.direction,
autoplay: this.interval ? {
delay: this.interval,
disableOnInteraction: false
} : false,
slidesPerView: 1,
loop: this.data.length <= 1 ? false : this.loop,
pagination: {
el: this.pagination ? '.swiper-pagination' : null
}
}
}
},
watch:{},
computed:{},
methods:{},
created(){},
mounted(){}
}
</script>
<style lang="scss" scoped>
</style>1
收起
正在回答
4回答
同学你好,1、这个没有自动轮播是因为homeslider中interval: 0,设置为0是不自动轮播的。想要自动轮播,需要改为其他值,例:300

2、如下,homeslider文件中,这个值建议设置我水平滚动。例:

3、sliderindex中的,单词应该是swiperOption。

4、sliderindex中的,如下,这里不需要data

若能帮助到你,望采纳。
祝学习愉快!
慕无忌6236884
2018-11-16 09:30:13
我看视屏在十分钟的时候也有这个错误。。。。但在老师写入swiper-slider之后,错误就消失了且开始自动轮播。。。我按着视屏的代码做了一遍,还是只能自己手动滑动,swiperOptions还是undefined。为什么呢
慕无忌6236884
2018-11-15 22:33:12
我看了下报错提示。。。。错误的地方都是在swiperOptions这个地方错的,把有关swiperOptions这个关键字的数据和标签删掉就不报错 了。。。但是这样子的话参数也用不了了啊
热门框架Vue开发WebApp 18版
- 参与学习 人
- 提交作业 209 份
- 解答问题 3299 个
本路径是通过ES6基础知识、运用Zepto、Swiper、fullPag等移动端常用工具包、以及当下流行框架Vue,结合多个实战案例,还原真实开发场景,最终实现手机端购物商城网页开发。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星