Vue+Element-UI实现轮播图

<template>
    <div>
         <el-carousel :interval="5000" height="36rem" @change="changeImg" indicator-position="outside">
            <el-carousel-item v-for="(item,index) in images" :key="index">
            <el-image
                :class="className"
                style="width:100%; height:100%"
                :src="item.idView"
                fit="fit"></el-image>
            </el-carousel-item>
        </el-carousel>
    </div>
</template>
<script>
export default {
    name: "Index",
    data() {
        return {
            images: [
                {id: 0, idView: require('../assets/homeImages/1.png')},
                {id: 1, idView: require('../assets/homeImages/2.jpg')},
                {id: 2, idView: require('../assets/homeImages/3.jpg')},
                {id: 3, idView: require('../assets/homeImages/4.jpg')},
                {id: 4, idView: require('../assets/homeImages/5.jpg')},
            ],
            className: "",
        }
    },
    mounted() {
        this.className = "lun-img-two";
        setTimeout(() => {
            this.className = "lun-img";
        }, 300);
    },
    methods: {
        changeImg: function (e) {
            this.className = "lun-img-two";
            setTimeout(() => {
                this.className = "lun-img";
            }, 300);
        }
    }
}
</script>
<style scoped>
    .lun-img {
        transition: all 4s;
        transform: scale(1.5);
    }
    .lun-img-two {
        transform: scale(1);
    }
    .el-carousel__item.is-animating {
        transition: transform 1s ease-in-out;
    }
</style>
  • 5
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当然!下面是一个基于Vue.js和Element UI的多功能首页的示例: 1. 在src/views文件夹下创建Home.vue组件,作为首页的主要内容。 ```vue <template> <div class="home"> <h1>Welcome to Home Page</h1> <!-- 添加你想要展示的内容 --> </div> </template> <script> export default { // 组件逻辑代码 } </script> <style scoped> /* 组件样式 */ </style> ``` 2. 在src/components文件夹下创建Navbar.vue组件,作为顶部导航栏。 ```vue <template> <nav class="navbar"> <ul> <li><a href="#">Home</a></li> <!-- 添加其他导航栏项 --> </ul> </nav> </template> <script> export default { // 组件逻辑代码 } </script> <style scoped> /* 组件样式 */ </style> ``` 3. 在src/App.vue文件中,将Navbar组件和Home组件添加到首页。 ```vue <template> <div id="app"> <Navbar /> <router-view /> </div> </template> <script> import Navbar from './components/Navbar.vue' export default { name: 'App', components: { Navbar } } </script> <style> /* 全局样式 */ </style> ``` 4. 在src/main.js文件中,添加Element UI的引入和全局样式。 ```javascript import Vue from 'vue' import App from './App.vue' import ElementUI from 'element-ui' import 'element-ui/lib/theme-chalk/index.css' Vue.use(ElementUI) Vue.config.productionTip = false new Vue({ render: h => h(App), }).$mount('#app') ``` 现在,你可以在Home.vue组件中添加任何你想要展示的内容,比如轮、卡片、列表等等。在Navbar.vue组件中,你可以添加其他导航栏项并进行相应的路由配置。 这个示例只是一个基本的多功能首页的示例,你可以根据具体的需求进行扩展和修改,添加更多的功能和组件。希望这个示例对你有帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值