滑块显示不出来

来源:5-18 tabs组件 - 实现滑块的滚动 - 01

weixin_慕仔6263612

2022-06-14

图片描述

<template>
<view class="tab-container">
    <view class="tab-box">
      <scroll-view
        id="_scroll"
        scroll-x
        class="scroll-view"
        scroll-with-animation
        :scroll-left="scrollLeft"
      >
        <view class="scroll-content">
          <view class="tab-item-box">
            <block v-for="(item, index) in tabData" :key="index">
              <view
                class="tab-item "
                @click="onClick(index)"
				:class="{'tab-item-active':activeIndex===index }">
              {{ item.label || item }}</view>
           
            </block>
            
          </view>
           <view
            class="underLine"
            :style="{
              transform: 'translateX(' + slider.left + 'px)',
            }"
          />1111111111111111111111111111111111111
        </view>
		  </scroll-view>
       
    </view>
    
  </view>
</template>

<script>
	export default {
		name:"my-tabs",
		props:{
			//获取父组件传过来的样式
			config:{
				type:Object,
				default:()=>{return {};}
			},
			//数据
			tabData:{
				type:Array,
				default:()=>{
					return [];
				}
			},
			//选中项
			

		},
		data() {
			return {
				activeIndex:0,
        slider:{
          left:0
        },
         scrollLeft: 0,
				
			};
		},
		
		methods:{
            onClick(val){
				this.activeIndex=val
				// console.log(this.defaultIndex);
		
		     
			}
		}
	}
</script>

<style lang="scss" scoped>
  .tab-container {
  font-size: $uni-font-size-base;
  height: 45px;
  line-height: 45px;
  background-color: $uni-bg-color;
  .tab-box {
    width: 100%;
    height: 45px;
    display: flex;
    position: relative;
    .scroll-view {
      white-space: nowrap;
      width: 100%;
      height: 100%;
      box-sizing: border-box;
      .scroll-content {
        width: 100%;
        height: 100%;
        position: relative;

        .tab-item-box {
          height: 100%;
      
          .tab-item {
            height: 100%;
            display: inline-block;
            text-align: center;
            padding: 0 15px;
            position: relative;
            text-align: center;
            color: $uni-text-color;
		
             &-active {
              color: $uni-text-color-hot;
            }
          }
        }
        .underLine{
         position: absolute;
          height: 30px;
          width:24px;
          background-color: red;
          border-radius: 3px;
          transform: .5s;
        
     
         
        }
      
      }
    }
  }

 
  
}
</style>
写回答

1回答

Sunday

2022-06-14

你好

这个是 明显的 css 问题导致的。可以参考下课程的css 代码。

0
0

uni-app从入门到进阶 系统完成项目实战

专门为小程序0基础学员而设,让你拥有能上线的作品

1106 学习 · 743 问题

查看课程