npm install --save swiper
第二步:写template。
轮播图是一个列表,所以这里使用到了v-for来遍历,轮播的部分是swiper-slide元素。我把图片路径绑定到了style属性上面。
<img :src=“item.url”/>
</div>
</div>
</div>
第三步:编写Banner.vue的JavaScript代码。
根据swiper的官方教程,我们需要实例化swiper。
1、导入swiper;
2、导入swiper的css;
3、通过获取图片数据listImg;
4、mounted类似react中的componentDidMount方法,实例化swiper必须等到dom渲染完成才能操作。
<script>
import Swiper from ‘swiper’;
import ‘swiper/dist/css/swiper.min.css’;
export default {
data(){
return {
//图片路径
listImg:[
{url:‘…/…/…/static/01.jpg’},
{url:‘…/…/…/static/02.jpg’},
{url:‘…/…/…/static/03.jpg’}
]
}
},
mounted() {
console.log(‘mounted’, this)
var mySwiper = new Swiper (‘.swiper-container’, {
loop: true,
pagination: {
el: ‘.swiper-pagination’,
},
// 如果需要前进后退按钮
navigation: {
nextEl: ‘.swiper-button-next’,
prevEl: ‘.swiper-button-prev’,
},
autoplay: {
disableOnInteraction: false,
},
})
}
}
</script>
第四步:写css样式
<style>
.swiper-container {width: 100%; height: 10rem;}
.swiper-wrapper {width: 100%; height: 100%; }
.swiper-slide { width: 100%; height: 100%;}
.swiper-pagination-bullet { width:0.833rem;
height: 0.833rem;display: inline-block; background: #7c5e53; }
js基础
1)对js的理解?
2)请说出以下代码输出的值?
3)把以下代码,改写成依次输出0-9
4)如何区分数组对象,普通对象,函数对象
5)面向对象、面向过程
6)面向对象的三大基本特性
7)XML和JSON的区别?
8)Web Worker 和webSocket?
9)Javascript垃圾回收方法?
10)new操作符具体干了什么呢?
11)js延迟加载的方式有哪些?
12)WEB应用从服务器主动推送Data到客户端有那些方式?
{ width:0.833rem;
height: 0.833rem;display: inline-block; background: #7c5e53; }
js基础
1)对js的理解?
2)请说出以下代码输出的值?
3)把以下代码,改写成依次输出0-9
4)如何区分数组对象,普通对象,函数对象
5)面向对象、面向过程
6)面向对象的三大基本特性
7)XML和JSON的区别?
8)Web Worker 和webSocket?
9)Javascript垃圾回收方法?
10)new操作符具体干了什么呢?
11)js延迟加载的方式有哪些?
12)WEB应用从服务器主动推送Data到客户端有那些方式?
[外链图片转存中…(img-FjQRFn6R-1718460792162)]
[外链图片转存中…(img-ag8tPSBV-1718460792163)]