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 不写也会滚动

相关推荐
V+zmm101341 小时前
基于微信小程序的乡村政务服务系统springboot+论文源码调试讲解
java·微信小程序·小程序·毕业设计·ssm
还这么多错误?!1 小时前
uniapp微信小程序,使用fastadmin完成一个一键获取微信手机号的功能
微信小程序·小程序·uni-app
_院长大人_1 小时前
微信小程序用户信息解密 AES/CBC/NoPadding 解密失败问题
微信小程序·小程序
web135085886352 小时前
uniapp小程序使用webview 嵌套 vue 项目
vue.js·小程序·uni-app
guanpinkeji2 小时前
废品回收小程序:助力企业转型发展
小程序·小程序开发·小程序制作·回收·废品回收小程序·废品回收
407指导员3 小时前
uniapp 微信小程序 页面部分截图实现
微信小程序·小程序·uni-app
三木吧5 小时前
开发微信小程序的过程与心得
人工智能·微信小程序·小程序
Kika写代码5 小时前
【微信小程序】3|首页搜索框 | 我的咖啡店-综合实训
微信小程序·小程序
金金金__5 小时前
微信小程序:解决顶部被遮挡的问题
微信小程序·小程序
zhulangfly16 小时前
Wux weapp 组件库的 bug—— wux-picker选择器组件无法正确初始化到选定的value
小程序·wux weapp