這個(gè)功能我感覺(jué)在任何項(xiàng)目中都會(huì)涉及到,今天我就把我的實(shí)現(xiàn)方法跟大家分享一下,有不對(duì)的地方還請(qǐng)指出,我好更新。
下面是整體代碼,我把輪播圖單獨(dú)做了一個(gè)組件,大家可以拿來(lái)就用,具體代碼如下:
<template> <div class="content"> <div class="focus"> <!-- focus begin --> <swiper :options="swiperOption"><!-- map是數(shù)組 這里我們用v-for把數(shù)據(jù)循環(huán)出來(lái) --> <swiper-slide v-for="item in map"> <a :href="item.i_route" rel="external nofollow" target="_blank"></a> </swiper-slide> <div class="swiper-pagination" slot="pagination"></div> </swiper> <!-- focus end --> </div> </div></template><script>//下面我們引用兩個(gè)插件,當(dāng)然,在使用之前請(qǐng)先安裝//安裝方法:npm install vue-awesome-swiper --save import VueAwesomeSwiper from 'vue-awesome-swiper' import { swiper, swiperSlide } from 'vue-awesome-swiper' export default { data() { return { swiperOption: { autoplay: 5000, initialSlide: 1, loop: true, pagination: '.swiper-pagination', paginationClickable: true, onSlideChangeEnd: swiper => { //console.log('onSlideChangeEnd', swiper.realIndex) } } } }, mounted () { this.bannerInfo(); }, components: { swiper, swiperSlide }, methods: { //輪播圖初始化 bannerInfo() {//通過(guò)接口獲取圖片數(shù)據(jù) this.$fetch('get/image/list').then(res => { if(res.errCode == 200) { this.map = res.errData; } }); } } }</script>以上就是實(shí)現(xiàn)輪播圖的全部代碼,有興趣的朋友可以試試看啦,希望大家繼續(xù)關(guān)注我們的網(wǎng)站!想要學(xué)習(xí)VUE的可以繼續(xù)關(guān)注本站。
新聞熱點(diǎn)
疑難解答
圖片精選