微信小程序> 微信小程序:6.一个input输入框

微信小程序:6.一个input输入框

浏览量:994 时间: 来源:mkmin

封了一个输入框的组件,大概的逻辑是:

1.输入框监听input事件,confirm事件,当数据发生变化时,反馈给外界2.要带上一个删除图标的样式

不是很麻烦,就直接吧代码贴上来

view class='component'  view class='inputbox'    image class='image' src="../../assets/common/ic_search.png" /image    input class='input' bindinput='hginput' bindconfirm='hgconfirm' type='text' placeholder='{{placeholder}}' type='{{type}}' value='{{value}}' confirm-type='搜索' /    icon wx:if='{{value}}' bindtap="clearValue" class="icon" type='clear' size="16"/icon  /view/view
let that;Component({  properties: {    // 初始化的输入框的值    value: {      type: String,      value: '',      observer(new_value, old_value) {        this.data.value = new_value;        this.triggerEvent("hgchange", this.data.value);      }    },    placeholder: {      type: String,      value: '请输入搜索内容'    },    //类型,默认为text    type: {      type: String,      value: "text"    }  },  ready() {    that = this;  },  methods: {    // input事件    hginput: function(data) {      this.setData({        value: data.detail.value      });    }, // commit事件    hgconfirm: function(data) {      this.triggerEvent("hgconfirm", this.data.value);    },    clearValue: function() {      this.setData({        value: ''      })      this.triggerEvent("hgchange", '');    }  }})

样式

.component {  background-color: #fff;  width: 750rpx;  padding-top: 20rpx;  padding-bottom: 20rpx;}.inputbox {  box-sizing: border-box;  margin-left: 25rpx;  border: 1px solid #ccc;  width: 700rpx;  border-radius: 16rpx;  height: 70rpx;  background: rgba(248, 248, 248, 1);}.image {  vertical-align: middle;  display: inline-block;  margin-top: 0rpx;  margin-left: 20rpx;  width: 50rpx;  height: 50rpx;}.input {  vertical-align: middle;  width: 500rpx;  margin-left: 10px;  display: inline-block;  height: 60rpx;  margin-top: 5rpx;  font-size: 24rpx;}.icon {  position: absolute;  display: block;  top: 34rpx;  right: 40rpx;  opacity: 0.8;  cursor: pointer;}

怎么使用就不多说了,界面大概这样

老规矩,代码地址:

git仓库https://github.com/hushilin01/public_mk_miniprogram

版权声明

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

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

最新资讯

热门模板

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