IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> JavaScript知识库 -> vue+element之carousel走马灯的使用(The use of vue+element carousel) -> 正文阅读

[JavaScript知识库]vue+element之carousel走马灯的使用(The use of vue+element carousel)

2022.10.13

大家好,今天我使用了vue+element实现走马灯的效果,类似于轮播图,可以进行一个图片的滑动。

Hello, everyone. Today, I used vue+element to realize the effect of rotating lights, which is similar to the wheel cast diagram, and can slide an image.

接下来就让我向大家展示如何使用它,并且解决其中遇到的问题。

Let me show you how to use it and solve the problems you encounter.

首先是element官方文档里面的写法。
The first is the way it's written in element's official documentation.

Element - The world's most popular Vue UI framework

<!-- carousel走马灯 -->
    <el-carousel
      :interval="3000"
      type="card"
      height="300px"
     
    >
      <el-carousel-item v-for="item in 4" :key="item">
        <h3 class="medium">{{ item }}</h3>
      </el-carousel-item>
    </el-carousel>
/* 走马灯样式 */
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}

这是最初始的写法,实现的效果如图:

This is the initial way of writing, and the effect is shown below:

看上去是不是和swipter轮播图差不多,所以当时我就想直接把跑马灯变成轮播图实现。?

It looks similar to swipter, so at that time I wanted to directly turn the running light into a wheel.

我的做法是这样的:

<el-carousel-item v-for="item in list" :key="item">

把4换成list,存放数组,然后就要新建一个数组。

I'm going to replace 4 with list, store the array, and then I'm going to create a new array.

data(){
    return{
      list:[
        {img:require('../assets/img/a.jpg')},
        {img:require('../assets/img/b.jpg')},
        {img:require('../assets/img/c.jpg')}
      ]
    }
  }

当时我把data后面的括号变成:以及return后面多加了:然后就导致我的list数组没有被定义。

I changed the parentheses after data to: and the parentheses after return to:, which resulted in my list being undefined.

接着就要用差值表达式渲染数据。

Then you render the data with a difference expression.

 <el-carousel-item v-for="item in list" :key="item">
       <img :src="item.img" >
      </el-carousel-item>

src和:src的区别,src是当成字符串解析,:src是当成变量解析。?

The difference between src, which is parsed as a string, and :src, which is parsed as a variable.

效果如图所示:

The effect is shown as follows:

这样就实现了一个swipter轮播图。?

In this way, a swipter rotcast graph is implemented.

大家喜欢的话点个赞,支持一下!

If you like it, click a like and support it!

  JavaScript知识库 最新文章
ES6的相关知识点
react 函数式组件 & react其他一些总结
Vue基础超详细
前端JS也可以连点成线(Vue中运用 AntVG6)
Vue事件处理的基本使用
Vue后台项目的记录 (一)
前后端分离vue跨域,devServer配置proxy代理
TypeScript
初识vuex
vue项目安装包指令收集
上一篇文章      下一篇文章      查看所有文章
加:2022-10-17 12:24:08  更:2022-10-17 12:24:35 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/17 16:43:12-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码