标签:cli height col order handle border index exp _id
<template> <div> <div v-for="(item,index) in this.titleVisibleData"> <div class="title">{{item}}</div> </div> <div> <button @click="moveLeft"><</button> <button @click="moveRight"> ></button> </div> </div> </template> <script> export default { name: "index", data(){ return{ titleData:[‘元素1‘,‘元素2‘,‘元素3‘,‘元素4‘,‘元素5‘,‘元素6‘], titleVisibleData:[] } }, methods:{ moveLeft(e){ if(this.titleData.length <= 3) return; this.handleMove(-1) }, moveRight(e){ if(this.titleData.length <= 3) return; this.handleMove(1) }, handleMove(type){ let _name = this.titleVisibleData[0],_idx=0,_temp=[]; console.log(type,_name) this.titleData.forEach((element,idx)=>{ if(element == _name){ _idx = idx; } }) let _start = _idx + type; for(let i=0;i<3;i++){ let _maxLenth = this.titleData.length; if(_start >= _maxLenth){ _start = 0; }else if(_start<0){ _start = _maxLenth - 1; } _temp.push(this.titleData[_start]); _start++; } this.titleVisibleData = _temp; }, }, mounted(){ this.titleVisibleData = this.titleData.slice(0,3) console.log(this.titleVisibleData,‘***‘) } } </script> <style lang="less"> .title{ margin-left: 20px; width: 100px; float:left; height: 50px; margin-right: 10px; border: 1px solid dodgerblue; line-height: 50px; } </style>
结果:
标签:cli height col order handle border index exp _id
原文地址:https://www.cnblogs.com/qing0228/p/14089650.html