78 lines
2.3 KiB
HTML
78 lines
2.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Document</title>
|
|
</head>
|
|
<body>
|
|
<div class="app">
|
|
<div>首页的轮播图</div>
|
|
<swiper :list="homeSwiper">
|
|
<template v-slot:default="{ item }">
|
|
<a :href=" 'info.html?id='+ item.id">
|
|
<img :src="item.img" alt="">
|
|
</a>
|
|
</template>
|
|
</swiper>
|
|
<hr>
|
|
<div>详情页的轮播图</div>
|
|
<swiper :list="infoSwiper">
|
|
<template v-slot:default="{ item }">
|
|
<img :src="item" alt="">
|
|
</template>
|
|
</swiper>
|
|
</div>
|
|
</body>
|
|
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
|
|
<script>
|
|
// 作用域插槽
|
|
Vue.component('swiper', {
|
|
data() {
|
|
return {
|
|
|
|
}
|
|
},
|
|
props: {
|
|
list: {
|
|
type: Array,
|
|
default: () => []
|
|
}
|
|
},
|
|
template: `
|
|
<div class="swiper">
|
|
<div class="swiper-wrapper">
|
|
<div class="swiper-slide" v-for="item,index in list" :key="index">
|
|
<slot :item="item"></slot>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`,
|
|
methods: {
|
|
clickData() {
|
|
|
|
}
|
|
}
|
|
});
|
|
|
|
new Vue({
|
|
el: '.app',
|
|
data:{
|
|
homeSwiper: [
|
|
{ id: 1, img: 'https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/4fd0e71e2ba1dac1a3b685417393e52c.jpg?thumb=1&w=720&h=360' },
|
|
{ id: 2, img: 'https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/8b2fe8572343d83cd84aa6d0c04b8390.jpg?thumb=1&w=720&h=360' },
|
|
],
|
|
infoSwiper: [
|
|
'https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/c6ff526b9d75342f0995778b56060b85.jpg?thumb=1&w=720&h=360',
|
|
'https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/beac5a54f4f4d93cb3f680a097b4f644.jpg?f=webp&w=1080&h=660&bg=F5F5F5'
|
|
]
|
|
},
|
|
methods:{
|
|
getChange(data) {
|
|
this.text = data
|
|
}
|
|
}
|
|
})
|
|
</script>
|
|
</html> |