vue+element轮播图

本文介绍了一个使用Vue.js结合Element UI实现的轮播图示例。该示例通过加载外部图片资源并利用Vue的数据绑定特性实现了响应式的轮播效果。代码中还包含了如何通过Ajax请求获取图片URL列表的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

vue+element轮播图

// An highlighted block
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>
<body>
<!-- 引入vue组件库 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>//vue请求库
<!-- 引入ElementUI组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<style type="text/css" media="all">
    @import url("//unpkg.com/element-ui@2.15.10/lib/theme-chalk/index.css");
.el-carousel__item h3 {
    color: #475669;
    font-size: 18px;
    opacity: 0.75;
    line-height: 300px;
    margin: 0;
  }
  
  .el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
  }
  
  .el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
  }
  .el-carousel__container {
    height: 88vh;
}

</style>
<div id="app">
<template>
  <el-carousel class="xh" indicator-position="outside">
    <el-carousel-item v-for="item in array">
        <img :src="'https://szxc.023700.com'+item" height="100%" width="100%" alt="" />
     </el-carousel-item>
  </el-carousel>
</template>
<script type="text/javascript" charset="utf-8">
 new Vue({
					el: '#app',
					data: {
					    array:[]
					},
					created: function() {
						this.ajax();
					},
					methods: {
					    ajax(){
					        let url ='';
							//发送get请求
							this.$http.get(url).then(function(res) {
							    this.array = res.body;
							}, function() {
								console.log('请求失败处理');
							});
					    }
					}
        
    })
</script>
</div>
</body>
</html>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值