一不小心数据获取多了,如何减少轮播图的数据获取
参考代码:
<el-tag type="info" v-for="item in tagList.slice(0, 5)" :key="item.id">{{ item.name }} </el-tag>
只要加上一个.slice(0,5)就可以了
<template> <div> <el-carousel :interval="4000" type="card" height="400px" style="margin-bottom: 15px;"> <el-carousel-item v-for="item in videoList.slice(0,5)" :key="item.id"> <router-link :to="'/video?video=' + item.id" > <img :src=getImgURL(item.id) style="width: 100%;height: 100%"> </router-link> </el-carousel-item> </el-carousel> <div style="margin-right: 4%;display: flex;flex-wrap:wrap;align-content:space-between;"> <el-col :span="5" v-for="item in videoList" :key="item.id" :offset="1" style="margin-bottom: 25px;"> <el-card :body-style="{ padding: '0px' }" style="padding-bottom: 17px"> <router-link :to="'/video?video=' + item.id" style="line-height: 0;color: black;text-decoration:none;"> <img :src="getImgURL(item.id)" style="width: 100%;height: 100%; margin-bottom: 7px;"> <!-- <template #footer>{{ item.name }}</template> --> <!-- <p>{{ item.name }}</p> --> <!-- <template #footer>Footer content</template> --> <span style="line-height: 17px;">{{item.name}}</span> </router-link> </el-card> </el-col> </div> <!-- <el-card style="max-width: 480px;max-height: 120px"> <template #header> <div class="card-header"> <span>Card name</span> </div> </template> <p v-for="o in 4" :key="o" class="text item">{{ 'List item ' + o }}</p> <template #footer>Footer content</template> </el-card> --> </div> </template> <script> import axios from "axios"; export default { data(){ return { videoList:[], searchForm:{ id:"" }, } }, methods:{ getVideoList(){ axios.get("/videolist").then((res)=>{ this.videoList = res.data }) }, // getImgURL(imgId){ // return "http://localhost:" // } getImgURL(imgId){ return "http://localhost:9090/static/img/"+ imgId + ".jpg" } }, created(){ this.getVideoList(); } } </script> <style scoped lang="less"> * { margin: 0; padding: 0; } // 走马灯样式 指示器按钮 /deep/ .el-carousel__button { width: 10px; height: 10px; border: none; border-radius: 50%; background-color: rgba(0, 0, 0, 0.2); } // 指示器激活按钮 /deep/ .is-active .el-carousel__button { background: #3f8ec8; } .el-main{ line-height: 0px !important; } </style>
好了,一只可爱的狗狗呈现在面前^_^
参考资料:
vue实现【接口数据渲染随机显示】和【仅显示前五条数据】_js数据渲染只显示前5条-CSDN博客