1.自己写一个swiper组件,注意组件名最好不要用swiper,注意设置swiper的高度,因为他有默认,其实就和写小程序一样,不要慌。直接复制用就行了,要是你有接口,就改成v-for循环起来就可以了。
<template>
<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
<swiper-item>
<view class="swiper-item">
<image src="../../static/img/dy.jpg" mode=""></image>
</view>
</swiper-item>
<swiper-item>
<view class="swiper-item">
<image src="../../static/img/dy.jpg" mode=""></image>
</view>
</swiper-item>
</swiper>
</template>
<script>
</script>
<style>
swiper{
width: 100%;
height: 400rpx;
}
.swiper-item image{
width: 100%;
height: 400rpx;
}
</style>
2.注册组件并使用,哪里需要在哪里引入。就和vue中一样。
<template>
<view class="index">
<view class="f-active-color">
首页
<index-swiper></index-swiper>
</view>
</view>
</template>
<script>
import indexSwiper from '@/components/index/indexSwiper.vue';
export default {
data() {
return {
title: 'Hello'
}
},
components:{
indexSwiper
},
onLoad() {
},
methods: {
}
}
</script>
<style>
/* 引入公共样式 */
@import "../../common/common.css";
</style>
版权声明:本文为zhangli0421原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。