封装微信小程序中input组件组件

组件样式
在这里插入图片描述

参数类型示例
passwordBoolean(是否是密码类型)password
placeholderString (提示词)请输入
nameString (form表单中name值)name
maxlengthNumber (最大输入长度 默认140)10
disableddisabled (是否禁用)disabled
mustBoolean(是否必填)true
unitString (单位)kg
jiantouBoolean (是否显示箭头)true
valueString (input框中value值)LGAG4DX39F3013734
<view class="row row-class">
  <text class="{{must == true ? 'must' : ''}}">{{must?'*':''}}{{title}}</text>
  <input type="{{type}}"
   password="{{password}}" 
   placeholder="{{placeholder}}" 
   name="{{name}}" 
   value="{{value}}"
    bindinput="_textInput" 
    maxlength="{{maxlength}}"
    disabled="{{disabled}}" 
    placeholder-class="input-placeholde" 
    cursor-spacing='140' />
  <text class="right">
     <text>{{unit}}</text>
     <text class="{{jiantou == true ? 'iconfont iconyoujiantou' : ''}}"></text>
  </text>
</view>
/* component/tow-row-login/tow-row-login.wxss */
@import "../../utils/iconfont.wxss";/*引入字体图标*/

.input-row {
  background-color: white;
  height: 44px;
  display: flex;
  flex-direction: row;
  align-items: center;
  padding-left: 15px;
  padding-right: 15px;
}

.input-row text {
  margin-right: 8px;
  font-size: 21px;
  color: #108ee9;
}

.input-row input {
  flex: 1;
  font-size: #bbb;
  color: #333;
}

.input-placeholde {
  color: #bbb;
  font-size: 16px;
}

.line {
  border-bottom: 2rpx solid #ddd;
}

.row .right {
  width: 45rpx;
}

.row .iconfont {
  width: 50rpx;
  font-size: 20px;
  color:  #333;
}

  properties: {
    title: { //左侧标题
      type: String,
      value: ""
    },
    type: {//输入文本类型
      type: String,
      value: "text"
    },
    placeholder: { //输入框提示词
      type: String,
      value: "请输入"
    },
    value: { //输入框默认值
      type: String,
      value: ""
    },
    maxlength: { //输入框最大长度
      type: Number,
      value: 140
    },
    password: { //输入框是否是密码类型
      type: Boolean,
      value: false
    },
    name: { //输入框在form表单中的name
      type: String,
      value: ""
    },
    unit: {
      type: String,
      value: ""
    },
    must: { //是否必填
      type: Boolean,
      value: false
    },

    jiantou: { //右箭头
      type: Boolean,
      value: false
    },

    disabled: { //是否禁用
      type: Boolean,
      value: false,
      observer: function(newVal, oldVal) {
        if (newVal == true) {
          this.setData({
            placeholder: "无"
          })
        }
      }
    }
  },
  externalClasses: ['row-class'],
  behaviors: ['wx://form-field'],
  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {

    /**
     * 输入框内容变化回调
     */
    _textInput: function(e) {
      this.setData({
        value: e.detail.value
      })
    }
  }
<form bindsubmit="save">
     <row-input title="整备质量" name="conditionQuality" row-class="line" type="digit" unit="kg" placeholder="请输入整备质量" />
</form>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

万水千山走遍TML

您的鼓励,将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值