84 lines
2.2 KiB
HTML
84 lines
2.2 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">
|
|
<swiper :arr="swiper" @change="goInfo">
|
|
<template v-slot:default="{ item }">
|
|
<img :src="item.img" alt="">
|
|
</template>
|
|
</swiper>
|
|
|
|
<h2>父组件</h2>
|
|
|
|
<swiper :arr="swiper" @change="fangda">
|
|
<template v-slot:default="{ item }">
|
|
<p>{{ item.id }}</p>
|
|
</template>
|
|
</swiper>
|
|
|
|
</div>
|
|
</body>
|
|
<script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>
|
|
<script>
|
|
|
|
|
|
var swiper = {
|
|
template: `
|
|
<div class="swiper">
|
|
<div class="swiper-wrapper">
|
|
<div class="swiper-slide" v-for="item,index in arr" @click="typeClick(item,index)">
|
|
<slot :item="item"></slot>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`,
|
|
props: {
|
|
arr: {
|
|
default: () => [],
|
|
type: Array
|
|
}
|
|
},
|
|
data() {
|
|
return {}
|
|
},
|
|
methods: {
|
|
typeClick(item,index) {
|
|
item.index = index;
|
|
this.$emit("change", item)
|
|
}
|
|
}
|
|
}
|
|
|
|
new Vue({
|
|
el: '.app',
|
|
data: {
|
|
swiper: [
|
|
{ id: 1, img: 'https://img.alicdn.com/imgextra/i4/6000000000247/O1CN016OonHt1DhAeHc2POy_!!6000000000247-2-octopus.png' },
|
|
{ id: 2, img: 'https://img.alicdn.com/imgextra/i4/6000000004607/O1CN01iyHGBo1ju3Ueo5MZr_!!6000000004607-0-octopus.jpg' },
|
|
{ id: 3, img: 'https://img.alicdn.com/imgextra/i1/6000000002571/O1CN011s3nON1UrZ6i7EyPo_!!6000000002571-0-octopus.jpg' },
|
|
]
|
|
},
|
|
methods: {
|
|
goInfo(res) {
|
|
console.log("进详情:",res);
|
|
},
|
|
fangda(res) {
|
|
console.log("放大:",res);
|
|
}
|
|
},
|
|
components: {
|
|
// swiper: swiperComponent
|
|
swiper
|
|
}
|
|
})
|
|
</script>
|
|
|
|
</html> |