2021-10-15 14:44:10 +00:00
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
class="layui-carousel"
|
2021-10-15 15:52:01 +00:00
|
|
|
lay-anim
|
2021-10-15 14:44:10 +00:00
|
|
|
lay-indicator="inside"
|
|
|
|
lay-arrow="always"
|
2021-10-16 15:41:35 +00:00
|
|
|
:style="{ width: width, height: height }"
|
2021-10-15 14:44:10 +00:00
|
|
|
>
|
2021-10-15 15:52:01 +00:00
|
|
|
<div carousel-item>
|
2021-10-16 15:41:35 +00:00
|
|
|
<slot></slot>
|
2021-10-15 14:44:10 +00:00
|
|
|
</div>
|
|
|
|
<div class="layui-carousel-ind">
|
|
|
|
<ul>
|
2021-10-16 15:41:35 +00:00
|
|
|
<li
|
|
|
|
v-for="ss in slots"
|
|
|
|
:key="ss"
|
|
|
|
:class="[ss.props.id === modelValue ? 'layui-this' : '']"
|
|
|
|
@click.stop="change(ss.props.id)"
|
|
|
|
></li>
|
2021-10-15 14:44:10 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
2021-10-16 15:41:35 +00:00
|
|
|
<button class="layui-icon layui-carousel-arrow" lay-type="sub" @click="prev"></button
|
|
|
|
><button class="layui-icon layui-carousel-arrow" lay-type="add" @click="next"></button>
|
2021-10-15 14:44:10 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script setup name="LayCarousel" lang="ts">
|
2021-10-16 15:41:35 +00:00
|
|
|
import { withDefaults, defineProps, provide, useSlots, ref } from 'vue'
|
|
|
|
|
|
|
|
const slot = useSlots() as any
|
|
|
|
const slots = slot.default && slot.default()
|
2021-10-15 15:52:01 +00:00
|
|
|
|
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
2021-10-16 15:41:35 +00:00
|
|
|
width?: string
|
|
|
|
height?: string
|
|
|
|
modelValue: string
|
2021-10-15 15:52:01 +00:00
|
|
|
}>(),
|
|
|
|
{
|
|
|
|
width: '100%',
|
2021-10-16 15:41:35 +00:00
|
|
|
height: '280px',
|
2021-10-15 15:52:01 +00:00
|
|
|
}
|
|
|
|
)
|
2021-10-16 15:41:35 +00:00
|
|
|
|
|
|
|
const active = ref(props.modelValue)
|
|
|
|
|
|
|
|
const emit = defineEmits(['update:modelValue','change','close'])
|
|
|
|
|
|
|
|
const change = function (id: any) {
|
|
|
|
emit('update:modelValue', id)
|
|
|
|
emit('change', id)
|
|
|
|
active.value = id
|
|
|
|
}
|
|
|
|
|
|
|
|
provide('active', active)
|
|
|
|
|
|
|
|
const prev = function() {
|
|
|
|
console.log("上一页")
|
|
|
|
}
|
|
|
|
|
|
|
|
const next = function() {
|
|
|
|
console.log("下一页")
|
|
|
|
}
|
2021-10-15 14:44:10 +00:00
|
|
|
</script>
|