scroll-view在小程序页面里实现滚动,uniapp项目

要实现红框中的区域进行滚动,scroll-view必须写高

javascript 复制代码
<template>
  <!-- 合同-待确认 -->
  <view class="viewport">
    <!-- 上 -->
    <view class="top-box">
      <!-- tab -->
      <view class="tabs">
        <text
          v-for="(item, index) in tabArr"
          :key="item.id"
          class="text"
          :class="{ active: index === activeIndex }"
          @tap="handleClickTab(item, index)"
          >{{ item.title }}</text
        >
      </view>
      <!-- tab的scroll-view -->
      <scroll-view
        v-for="(val, index) in tabArr"
        :key="val.id"
        v-show="activeIndex === index"
        :scroll-y="true"
        class="scroll-view"
      >
        <view v-show="activeIndex === 0" class="base-box">
          <view>33333333333</view>
          <view>33333333333</view>

          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
          <view>54555555553343</view>
        </view>
        <view v-show="activeIndex === 1" class="contract-content-box"></view>
        <view v-show="activeIndex === 2" class="service-plan-box"></view>
      </scroll-view>
    </view>
    <!-- 下 -->
    <view class="bottom-box">
      <!-- canvas -->
      <view class="canvas-box"></view>
      <!-- 按钮 -->
      <view class="btn-box">
        <view class="btn-save">
          <u-button type="primary" shape="circle" text="保存"></u-button>
        </view>
        <view class="btn-submit">
          <u-button color="#f59a23" type="primary" shape="circle" text="提交"></u-button>
        </view>
      </view>
    </view>

    <!-- 基本信息 -->
    <!-- <view class="base-info-box" v-show="activeIndex === 0">
      <BaseInfo></BaseInfo>
    </view> -->

    <!-- 合同内容 -->
    <!-- <view class="contract-content-box" v-show="activeIndex === 1">
      <ContractContent></ContractContent>
    </view> -->

    <!-- 服务计划 -->
    <!-- <view class="service-plan-box" v-show="activeIndex === 2">
      <ServicePlan></ServicePlan>
    </view> -->
  </view>
</template>

<script setup lang="ts">
import { onLoad, onReady } from "@dcloudio/uni-app"
import { ref } from "vue"
import BaseInfo from "./components/BaseInfo.vue"
import ContractContent from "./components/ContractContent.vue"
import ServicePlan from "./components/ServicePlan.vue"

// 高亮的下标
const activeIndex = ref(0)

const peopleId = ref()

const tabArr = ref([
  {
    id: 0,
    title: "基本信息",
  },
  {
    id: 1,
    title: "合同内容",
  },
  {
    id: 2,
    title: "服务计划",
  },
])

// 页面第1次加载生命周期
onLoad((option) => {
  console.log(option, "option-页面第1次加载生命周期拿到的参数-等确认合同")
  peopleId.value = option!.itemDataId
  console.log(peopleId.value, "peopleId.value-等确认合同")
})

// 页面第1次全部渲染完毕后调用这个生命周期
onReady(() => {})

// 点击tab
const handleClickTab = (item: any, index: any) => {
  console.log(item, "点击tab拿到的item")
  console.log(index, "点击tab拿到的index")
  activeIndex.value = index
}
</script>

<style lang="scss">
page {
  height: 100%;
  background-color: #fff;
  overflow: hidden;
}

.viewport {
  height: 100%;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  background-color: #f2f2f2;
  justify-content: space-between;
  overflow: hidden;
  // border: 1px solid orangered;
}

.tabs {
  display: flex;
  justify-content: space-evenly;
  height: 100rpx;
  line-height: 90rpx;
  margin: 20rpx 20rpx 0rpx 20rpx;
  font-size: 28rpx;
  border-radius: 10rpx;
  box-shadow: 0 4rpx 5rpx rgba(200, 200, 200, 0.3);
  color: #333;
  background-color: #fff;
  position: relative;
  z-index: 9;
  .text {
    margin: 0 20rpx;
    position: relative;
  }
  .active {
    &::after {
      content: "";
      width: 40rpx;
      height: 4rpx;
      transform: translate(-50%);
      background-color: #27ba9b;
      position: absolute;
      left: 50%;
      bottom: 24rpx;
    }
  }
}

.base-info-box {
  flex: 1;
}

.contract-content-box {
  flex: 1;
}

.service-plan-box {
  flex: 1;
}

.btn-box {
  border: 1px solid red;
  margin-bottom: 20rpx;
  display: flex;
  flex-direction: row;

  .btn-save {
    padding: 0 20rpx;
    width: 400rpx;
  }

  .btn-submit {
    padding: 0 20rpx;
    width: 400rpx;
  }
}

.bottom-box {
  width: 750rpx;
  height: 400rpx;
  border: 1px solid blue;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.top-box {
  flex: 1;
  width: 750rpx;

  border: 1px solid orangered;
  display: flex;
  flex-direction: column;
}

.scroll-view {
  height: 660rpx;
  border: 1px solid green;
  // flex: 1;
  // overflow-y: auto;
}

.base-box {
  height: 100%;
  background-color: pink;
  overflow-y: auto;
}
</style>

overflow-y:auto 不写也会滚动

相关推荐
丁总学Java9 分钟前
微信小程序,点击bindtap事件后,没有跳转到详情页,有可能是app.json中没有正确配置页面路径
微信小程序·小程序·json
说私域1 小时前
基于开源 AI 智能名片、S2B2C 商城小程序的用户获取成本优化分析
人工智能·小程序
mosen8681 小时前
Uniapp去除顶部导航栏-小程序、H5、APP适用
vue.js·微信小程序·小程序·uni-app·uniapp
qq22951165022 小时前
微信小程序的汽车维修预约管理系统
微信小程序·小程序·汽车
尚梦9 小时前
uni-app 封装刘海状态栏(适用小程序, h5, 头条小程序)
前端·小程序·uni-app
paopaokaka_luck14 小时前
基于Spring Boot+Vue的助农销售平台(协同过滤算法、限流算法、支付宝沙盒支付、实时聊天、图形化分析)
java·spring boot·小程序·毕业设计·mybatis·1024程序员节
Bessie23416 小时前
微信小程序eval无法使用的替代方案
微信小程序·小程序·uni-app
蜕变菜鸟16 小时前
小程序跳转另一个小程序
小程序
19 小时前
躺平成长-代码开发,利用kimi开发小程序(09)
小程序
1 天前
微信小程序运营日记(第四天)
微信小程序·小程序