The installation element UI
To install dependencies in the Vue project, enter the installation command NPM I element-uI-s in the terminal
Import dependencies from main.js:
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
Copy the code
Create a new Carousel.vue component
<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="No picture"/>
</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>
Copy the code
The introduction of the component
<template> <el-main style="border: #42B983 1px solid"> <Carousel></Carousel> </el-main> </template> <script> import Carousel from './utils/Carousel' export default { components: { Carousel } } </script>Copy the code
Achievements: