86 lines
2.2 KiB
HTML
86 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>swiper</title>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="app">
|
|
<swiper :arr="swiper" @change="gofo">
|
|
<template v-slot:default="{v}">
|
|
<img :src="v.img" alt="">
|
|
</template>
|
|
</swiper>
|
|
<h2>不同效果</h2>
|
|
<swiper :arr="swiper" @change="fangda">
|
|
<template v-slot:default="{v}">
|
|
<!-- <img :src="item.img" alt=""> -->
|
|
<p>{{ v.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="v,i in arr" @click="typeClick(v,i)">
|
|
<slot :v="v"></slot>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`,
|
|
props:{
|
|
arr:{
|
|
//数组默认值只能是方法返回空数组
|
|
default: () => [],
|
|
type:Array
|
|
}
|
|
},
|
|
data (){
|
|
return {}
|
|
},
|
|
methods:{
|
|
typeClick(v,i) {
|
|
v.i = i;
|
|
this.$emit("change",v)
|
|
}
|
|
}
|
|
}
|
|
|
|
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' },
|
|
]
|
|
|
|
},
|
|
//注册组件
|
|
components: {
|
|
swiper
|
|
},
|
|
methods:{
|
|
gofo(res){
|
|
console.log("进详情",res);
|
|
},
|
|
fangda(res){
|
|
console.log("放大",res);
|
|
}
|
|
}
|
|
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
</html> |