基于上篇文章,我们可以直接使用elementui组件
使用走马灯组件案例:
<script setup>
</script>
<template>
<div>
<el-carousel indicator-position="outside">
<el-carousel-item v-for="item in 4" :key="item">
<h3 text="2xl" justify="center">{{ item }}</h3>
</el-carousel-item>
</el-carousel>
</div>
</template>
<style scoped>
</style>
在elementui中,走马灯标签为:el-carousel
其他就是一些样式的设置,比如justify是使h3的内容居中,indicator-position用于描述某个指示器(如箭头、滑块、进度条上的点等)的位置。这些不属于element而是html属性
上述代码页面功能实现了,但是样式是一点没有,所以需要我们自己添加样式。。。
按你的喜好来,我添加的样式为:
<script setup>
</script>
<template>
<div>
<el-carousel indicator-position="outside">
<el-carousel-item v-for="item in 4" :key="item">
<h3 text="2xl" justify="center">{{ item }}</h3>
</el-carousel-item>
</el-carousel>
</div>
</template>
<style scoped>
.el-carousel__item h3 {
display: flex;
color: #475669;
opacity: 0.75;
line-height: 300px;
margin: 0;
}
.el-carousel__item:nth-child(2n) {
background-color: #99a9bf;
}
.el-carousel__item:nth-child(2n + 1) {
background-color: #d3dce6;
}
</style>
实现的页面效果:
更多组件和样式请参考:官网