scroll/index.vue文件有两个问题
来源:5-1 下拉刷新--变化提示文字
鹿人神经粉
2020-02-24 19:15:26
问题1:scroll/index.vue文件的这个是什么意思,干嘛的
问题2:pullDownText: '再拉,再拉就刷给你看',这个文字一直显示不出来,显示的是loading图片和加载中文字
<template>
<swiper :options="swiperOption" ref='swiper'> <!-- 这个参数是滚动条的参数 -->
<div class="mine-scroll-pull-down" v-if="pullDown"> <!-- pullDown默认是没有的,在home/index.vue文件没有传入pullDown什么都没有显示,传入pullDown显示loading -->
<me-loading inline :text="pullDownText"/> <!-- :text="pullDownText"的pullDownText是写在data里的 -->
</div>
<swiper-slide>
<slot></slot>
</swiper-slide>
<div class="swiper-scrollbar" v-if="scrollbar" slot="scrollbar"></div>
</swiper>
</template>
<script>
import {swiper, swiperSlide} from 'vue-awesome-swiper';
import MeLoading from 'base/loading';
import {
PULL_DOWN_HEIGHT,
// PULL_DOWN_TEXT_INIT,
PULL_DOWN_TEXT_START,
PULL_DOWN_TEXT_ING,
PULL_DOWN_TEXT_END,
PULL_UP_HEIGHT,
PULL_UP_TEXT_INIT,
PULL_UP_TEXT_START,
PULL_UP_TEXT_ING,
PULL_UP_TEXT_END
} from './config';
export default{
name: 'MeScroll',
components: {
swiper,
swiperSlide,
MeLoading
},
props: {
scrollbar: {
type: Boolean,
default: true
},
data: {
type: [Array, Object]
},
pullDown: {
type: Boolean,
default: false // pullDown默认是没有的
}
},
data() {
return {
pullDownText: '再拉,再拉就刷给你看',
swiperOption: {
direction: 'vertical',
slidesPerView: 'auto',
freeMode: true,
setWrapperSize: true,
scrollbar: {
el: this.scrollbar ? '.swiper-scrollbar' : null,
hide: true
},
on:{
sliderMove: this.scroll, // sliderMove事件
}
}
};
},
watch: {
data() {
this.update();// 检测data的变化,当data变化之后,我们来更新滚动条,怎么更新,直接调用update
}
}, // swiper的api:swiper.update 通过这个来更新滚动条 new Swiper(),实例的swiper(swiper.update这个指的是实例的swiper)
methods: {
update() {
// console.log(this. $refs.swiper); // 显示VueComponent对象 里面有属性swiper:swiper( 实例的swiper )
this.$refs.swiper && this.$refs.swiper.swiper.update(); // this.$refs.swiper这个存在的话调用swiper.update()
// 上面是供外部调用的api
// 下面供内部使用的
},
scroll(){
}
}
};
</script>
<style lang="scss" scoped>
.swiper-container {
// overflow: hidden;
width: 100%;
height: 100%;
};
.swiper-slide {
height: auto;
}//有了这个滚动条能拉动了,滚动条也显示出来了
// 滚动条:
// slidesPerView:一页里面能看到几张图片
// freeMode 自由滚动
// setWrapperSize 显示swiper-wrapper这个的高度
// hide 是否自动隐藏
// .swiper-container 可视区
// .swiper-container{
// overflow:hidden //因为是被里面的内容撑开了所以溢出隐藏,设置宽高100%才有用
// }
.mine-scroll-pull-down {
position: absolute;
left: 0;
width: 100%;
}
.mine-scroll-pull-down {
bottom: 100%; // 出可视区 默认是看不到的
height: 80px;
}
</style>
3回答
同学你好,传递过来的是text,并不是pullDownText
所以loading组件props中应该是text
data中再添加数据
自己修改测试下,祝学习愉快!
鹿人神经粉
提问者
2020-02-25
还是显示加载中,感觉base文件没有错呀
base/loading/index.vue
<template>
<div class="mine-loading" :class="{'mine-loading-inline':inline}">
<span class="mine-loading-indicator" v-if="indicator==='on'">
<slot><img src="./loading.gif" alt="loading"> </slot>
</span>
<span class="mine-loading-text" v-if="loadingText">{{loadingText}}</span>
</div>
</template>
<script>
export default{
name: 'MeLoading',
props: {
indicator: {
type: String,
default: 'on',
validator(value) {
return ['on', 'off'].indexOf(value) > -1;
}
},
loadingText: {
type: String,
default: '加载中...'
},
inline: {
type: Boolean,
default: false // inline这个是垂直的样式(默认的),父组件有传入inline才会显示水平的样式
}
}
};
</script>
<style lang="scss" scoped>
@import "~assets/scss/mixins";
//loading图片和加载中文字的当水平和垂直不同方向时的样式,动态的类(样式不固定,固定了就不能动态)
.mine-loading{ // 写在里面一般都是 &-inline,这里没有
text-align:center;
width: 100%;
height: 100%;
@include flex-center(column);
//这个带~ 不用加& 两个类同时存在(~兄弟选择器)
.mine-loading-indicator ~ .mine-loading-text{
margin-top: 6px;
}
//在大括号里面要加&
&.mine-loading-inline{//这里可以这样写 &-inline
flex-direction:row;
.mine-loading-indicator ~ .mine-loading-text {
margin-top: 0;
margin-left: 6px;
}
}
}
</style>
好帮手慕星星
2020-02-25
同学你好,问题解答如下:
1、data是从父组件传递过来的数据
type是判断数据类型,可能是数组或者对象类型
2、这边测试粘贴的代码效果没有问题,文字可以替换
建议重新测试。如果还有问题的话,可以将base/loading文件代码粘贴上来,老师帮助测试下。
祝学习愉快!
相似问题
回答 2