微信小程序> 微信小程序之一个小需求的UI布局方式

微信小程序之一个小需求的UI布局方式

浏览量:696 时间: 来源:天-涯-路

    有这么一个UI布局需求:上半部分是一个可变列表,下方底端有一个输入框布局,要求在列表长度较短时,输入框布局保留在底端;当列表长度够长时,输入框布局放在列表底端,可以随列表一起滚动。效果如下图所示:

    实现分析:如下图所示,A布局需要设定一个固定高度,如100vh, 超出部分可以滚动;B布局设定一个最小高度,如86%;C布局放在B布局下方即可。

    关键代码:

<template>  <div class="container">    <div class="content">      <div class="variable">        <div class="btn-container">           <button class="btn" @click="addItem">add item</button>          <button class="btn" @click="reduceItem">reduce item</button>        </div>        <ul>          <li v-for="item in items" :key="item.id">            <div class="item">{{item.name}}</div>          </li>        </ul>      </div>      <div class="item-input">        <input placeholder="填写备注,限制20个字符" maxlength="20" class="comment" v-model.lazy="comment" @change="getComment"/>      </div>    </div>  </div>  </template><script>export default {  data() {    return {      items: [        { name: '测试item' },        { name: '测试item' },        { name: '测试item' },        { name: '测试item' },        { name: '测试item' }      ]    }  },  methods: {    addItem() {      this.items.push({ name: '添加的测试item' })    },    reduceItem() {      this.items.splice(this.items.length - 1, 1)      console.log('length: ', this.items.length)    }  }}</script><style lang="scss" scoped>.content{  width: 100%;  height: 100vh;  overflow: scroll;}.variable {  width: 100%;  min-height: 86%;  flex-direction: column;}.comment {  width: 88%;  font-size: 9pt;  padding: 10rpx 20rpx;  border: 1px solid #e0e0e0;  border-radius: 4pt;  margin-top: 16rpx;  margin-bottom: 10rpx;}</style>

完整源码传送门:https://github.com/tianyalu/mpvue-ui-demo

 

微信小程序

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎