Vue2配合element 上下滚动文本组件

该代码示例展示了如何在Vue.js应用中结合Element-UI库创建一个垂直方向的轮播组件。页面包含一个自定义的telegraph类样式,使用了Element-UI的carousel组件来展示数据列表,并实现了上翻下翻的导航功能。
摘要由CSDN通过智能技术生成

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <link
      rel="stylesheet"
      href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"
    />
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>

    <style>
      * {
        padding: 0;
        margin: 0;
        box-sizing: border-box;
      }
      #app {
        height: 100vh;
        width: 100vw;
        display: flex;
      }
      .telegraph {
        margin: auto;
        background-color: #eaf5ff;
        border-radius: 12px;
        height: 24px;
        line-height: 24px;
        color: #5791ff;
        font-size: 12px;
        padding: 0 20px;
        width: 400px;
        display: flex;
      }

      .telegraph .carousel {
        width: 100%;
      }

      .telegraph .count {
        color: #a7abb3;
        font-size: 12px;
        min-width: max-content;
        display: flex;
        align-items: center;
      }

      .direction {
        display: flex;
        flex-direction: column;
      }
      .direction i {
        line-height: 7px !important ;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <div class="telegraph">
        <el-carousel
          height="24px"
          class="carousel"
          ref="carousel"
          indicator-position="none"
          direction="vertical"
          autoplay
        >
          <el-carousel-item v-for="(item,index) in info" :key="index">
            <div>{{item.name}}</div>
          </el-carousel-item>
        </el-carousel>
        <div class="count">
          <span>共计{{info.length}}条</span>
          <div class="direction">
            <i class="el-icon-caret-top" @click="performancePunishsTb(1)"></i>
            <i
              class="el-icon-caret-bottom"
              @click="performancePunishsTb(0)"
            ></i>
          </div>
        </div>
      </div>
    </div>

    <script>
      new Vue({
        el: "#app",
        data() {
          return {
            info: [
              {
                name: "莎拉",
              },
              {
                name: "六花",
              },
              {
                name: "黑子",
              },
            ],
          };
        },
        methods: {
          performancePunishsTb(type) {
            const func = {
              1: () => {
                this.$refs.carousel.prev();
              },
              0: () => {
                this.$refs.carousel.next();
              },
            };

            func[type] ? func[type]() : console.error("传参不对");
          },
        },
      });
    </script>
  </body>
</html>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值