• 新闻轮播图


    一、效果图

    二、vue中html部分

    1. <div class="swiper-container" ref="swiperDom">
    2. <div class="swiper-wrapper">
    3. <div class="swiper-slide" v-for="(item,index) in newsImageList" :key="index">
    4. <img class="image" :src="item.imageUrl">
    5. div>
    6. div>
    7. <div class="swiper-pagination">div>
    8. <div class="title pl-12">{{ swiperTitle }}div>
    9. div>

    三、vue中相关js代码

    1. let state = reactive({
    2. timer:null,
    3. newsImageList:[],
    4. async getImageList(){
    5. let data={
    6. page:PAGEITEM.page,
    7. size:PAGEITEM.size,
    8. }
    9. let res = await getImageList(data)
    10. if(res.code===SUCCESS_CODE){
    11. state.newsImageList=res.data.records
    12. }else{
    13. state.newsImageList=[]
    14. }
    15. },
    16. swiper: {},
    17. swiperTitle:'',
    18. initSwiper() {
    19. //@ts-ignore
    20. state.swiper = new Swiper(swiperDom.value, {
    21. // Swiper的配置选项
    22. pagination: {//页脚(标题部分)
    23. el: '.swiper-pagination',
    24. },
    25. on:{//这里是为了实现手写title获取
    26. transitionEnd : function(e){
    27. let index=(e.activeIndex===(state.newsImageList.length+1))?1:e.activeIndex
    28. state.swiperTitle=state.newsImageList[index-1].title
    29. },
    30. },
    31. //自动轮播
    32. autoplay: {
    33. delay: 2500,//时间 毫秒
    34. disableOnInteraction: false,//用户操作之后是否停止自动轮播默认true
    35. },
    36. loop:true,//循环 最后面一个往后面滑动会滑到第一个
    37. });
    38. },
    39. });
    40. onMounted(async () => {
    41. await state.getImageList()
    42. state.timer = setTimeout(() => {
    43. state.initSwiper();
    44. }, 100)
    45. });
    46. onUnMounted(()=>{
    47. state.timer=null
    48. })

    四、less代码

    1. .swiper-container {
    2. width: 100%;
    3. height: 100%;
    4. position:relative;
    5. :deep(.swiper-slide) {
    6. width: 100%;
    7. height: 100%;
    8. img {
    9. width: 100%;
    10. height: 100%;
    11. }
    12. }
    13. .title{
    14. height: 50px;
    15. line-height: 50px;
    16. position: relative;
    17. top:-50px;
    18. color:#fff;
    19. z-index: 10;
    20. width: 70%;
    21. .ellipsis;
    22. }
    23. :deep(.swiper-pagination){
    24. background: rgba(00,00,00,.7);
    25. height: 50px;
    26. bottom: 0;
    27. display: flex;
    28. justify-content: flex-end;
    29. align-items: center;
    30. padding-right: 24px;
    31. .swiper-pagination-bullet {
    32. background: rgba(255,255,255,.9);
    33. }
    34. .swiper-pagination-bullet-active{
    35. background: #fff;
    36. }
    37. }
    38. }

  • 相关阅读:
    MySQL 事务一致性的视线
    VirtualBox虚拟机安装Win10企业版
    Substance Painter 的一些玩法笔记
    海康、大华等IPC解码上墙,PC上平台同时查看方案
    u盘文件夹被隐藏怎么恢复正常?
    Mybatis-SQL分析组件
    LwIP笔记01:LwIP入门
    解释Java虚拟机(JVM)的工作原理
    JNI入门
    windows批处理命令
  • 原文地址:https://blog.csdn.net/weixin_59017683/article/details/132830142