element-ui图片走马灯应用

·  阅读 1766

安装element ui

一、在Vue项目中安装依赖,在终端输入安装指令:npm i element-ui -S

二、导入依赖,在main.js引入:

image.png

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);
复制代码

新建Carousel.vue组件

image.png


<template>
  <el-carousel indicator-position="none" loop="true" interval="2000" trigger="click">
    <el-carousel-item v-for="item in images" :key="item">
       <img :src="item.url" alt="无图片"/>
    </el-carousel-item>
  </el-carousel>
</template>

<script>
  export default {
    name: "Carousel",
    data() {
      return {
        images: [
          { url: require("@/assets/1.jpg")},
          { url: require("@/assets/2.jpg")},
          { url: require("@/assets/3.jpg")},
          { url: require("@/assets/4.jpg")},
          { url: require("@/assets/5.jpg")},
          { url: require("@/assets/logo.png")}
        ],
      };
    },
  };
</script>

<style scoped>
  .el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 150px;
    margin: 0;
  }

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

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

复制代码

引入组件

<template>
  <el-main style="border: #42B983 1px solid">
        <Carousel></Carousel>
      </el-main>
</template>

<script>
  import Carousel from './utils/Carousel'
  export default {
    components: {
      Carousel
    }
  }
</script>
复制代码

成果展示: image.png

分类:
前端
收藏成功!
已添加到「」, 点击更改