1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="js/vue.js"></script>
<link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css"> <script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script> <style> .swiper-container { width: 80%; height: 600px; } </style>
</head> <body> <div id="box">
<div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide" v-for="(data,i) in datalist" v-comp="{index:i,length:datalist.length}">
{{data}}
</div> </div> <div class="swiper-pagination"></div> <div class="swiper-button-prev"></div> <div class="swiper-button-next"></div>
<div class="swiper-scrollbar"></div> </div> </div> </body> <script> Vue.directive('comp', { inserted(el, input) { console.log(input.value) if (input.value.index === input.value.length - 1) { var mySwiper = new Swiper('.swiper-container', { loop: true, pagination: { el: '.swiper-pagination', }, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', },
scrollbar: { el: '.swiper-scrollbar', },
}) }
}, }) var vm = new Vue({ el: '#box', data: { datalist: [], }, mounted() { setTimeout(() => { this.datalist = ['111', '222', '333'] }, 2000) },
}) </script> </html>
|