标签:nta swiper export style 延迟加载 app 一加 this get
全局引入轮播图的js 和 css文件
<template>
<div>
<h1>轮播图案例</h1>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide" v-for="item in bannerList" :key="item.id">
<img :src="‘http://localhost:3000‘ + item.img" alt="" />
</div>
</div>
</div>
</div>
</template>
?
<script>
//引入核心库
import Swiper from "swiper";
import axios from "axios";
export default {
data() {
return {
bannerList: []
};
},
mounted() {
//组件一加载就调取接口
axios({
url: "/api/api/getbanner"
}).then(res => {
console.log(res, "响应");
if (res.data.code == 200) {
this.bannerList = res.data.list;
//延迟加载,下一次再去加载dom
console.log(this, "实例化");
//this.$nextTick(callback)
this.$nextTick(() => {
//组件一加载就调取轮播图
let swiper = new Swiper(".swiper-container", {
loop: true,
autoplay: {
delay: 2000
}
});
});
}
});
}
};
</script>
?
<style lang="">
.swiper-container {
width: 100%;
height: 100%;
}
?
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
?
/* Center slide text vertically */
display: