uView Input 输入框

简介: uView Input 输入框

去除fixedshowWordLimitshowConfirmBardisableDefaultPaddingautosize字段

此组件为一个输入框,默认没有边框和样式,是专门为配合表单组件u-form而设计的,利用它可以快速实现表单验证,输入内容,下拉选择等功能。

应该在u-form中嵌套u-form-item,再嵌套u-input去实现。

注意:

由于在nvue下,u-input名称被uni-app官方占用,在nvue页面中请使用u--input名称,在vue页面中使用u--input或者u-input均可。

#平台差异说明

App(vue) App(nvue) H5 小程序

#基本使用

  • 通过type设置输入框的类型,默认text
  • 通过placeholder设置输入框为空时的占位符
  • 通过border配置是否显示输入框的边框
  • 绑定@change事件
<template>
  <u--input
    placeholder="请输入内容"
    border="surround"
    v-model="value"
    @change="change"
  ></u--input>
</template>
<script>
  export default {
      data() {
        return {
          value: ''
        }
      },
      methods: {
        change(e) {
          console.log('change', e);
        }
      }
  }
</script>

copy

#输入框的类型

综述:输入框的类型可通过配置type来设置:

  1. text-文本输入键盘。
  2. number-数字输入键盘,app-vue下可以输入浮点数,app-nvue和小程序平台下只能输入整数。
  3. idcard-身份证输入键盘,微信、支付宝、百度、QQ小程序。
  4. digit-带小数点的数字键盘,App的nvue页面、微信、支付宝、百度、头条、QQ小程序。
  5. password-等同于设置passwordtrue的效果
#可清空字符

clearable设置为true,会在输入框后方增加一个清空按钮。

<template>
  <u--input
    placeholder="请输入内容"
    border="surround"
    clearable
  ></u--input>
</template>

copy

#下划线

通过设置属性borderbottom即可变成一个下划线

<template>
  <u--input
    placeholder="请输入内容"
    border="bottom"
    clearable
  ></u--input>
</template>

copy

#前后图标
  • 全后置图标可自由设置样式信息。
<template>
  <u--input
      placeholder="前置图标"
      prefixIcon="search"
      prefixIconStyle="font-size: 22px;color: #909399"
  ></u--input>
  <u--input
      placeholder="后置图标"
      suffixIcon="map-fill"
      suffixIconStyle="color: #909399"
  ></u--input>
</template>
<script>
</script>

copy

#前后插槽

通过设置slotprefixsuffix来指定前后插槽

<template>
  <view class="u-demo-block">
    <text class="u-demo-block__title">前后插槽</text>
    <view class="u-demo-block__content">
      <!-- 注意:由于兼容性差异,如果需要使用前后插槽,nvue下需使用u--input,非nvue下需使用u-input -->
      <!-- #ifndef APP-NVUE -->
      <u-input placeholder="前置插槽">
      <!-- #endif -->
      <!-- #ifdef APP-NVUE -->
      <u--input placeholder="前置插槽">
      <!-- #endif -->
        <u--text
          text="http://"
          slot="prefix"
          margin="0 3px 0 0"
          type="tips"
        ></u--text>
      <!-- #ifndef APP-NVUE -->
      </u-input>
      <!-- #endif -->
      <!-- #ifdef APP-NVUE -->
      </u--input>
      <!-- #endif -->
    </view>
    <view
      class="u-demo-block__content"
      style="margin-top: 15px;"
    >
      <!-- 注意:由于兼容性差异,如果需要使用前后插槽,nvue下需使用u--input,非nvue下需使用u-input -->
      <!-- #ifndef APP-NVUE -->
      <u-input placeholder="后置插槽">
      <!-- #endif -->
      <!-- #ifdef APP-NVUE -->
      <u--input placeholder="后置插槽">
      <!-- #endif -->
        <template slot="suffix">
          <u-code
            ref="uCode"
            @change="codeChange"
            seconds="20"
            changeText="X秒重新获取哈哈哈"
          ></u-code>
          <u-button
            @tap="getCode"
            :text="tips"
            type="success"
            size="mini"
          ></u-button>
        </template>
      <!-- #ifndef APP-NVUE -->
      </u-input>
      <!-- #endif -->
      <!-- #ifdef APP-NVUE -->
      </u--input>
      <!-- #endif -->
    </view>
  </view>
</template>
<script>
  export default {
    data() {
      return {
        tips: '',
        value: ''
      }
    },
    watch: {
      value(newValue, oldValue) {
        // console.log('v-model', newValue);
      }
    },
    methods: {
      codeChange(text) {
        this.tips = text;
      },
      getCode() {
        if (this.$refs.uCode.canGetCode) {
          // 模拟向后端请求验证码
          uni.showLoading({
            title: '正在获取验证码'
          })
          setTimeout(() => {
            uni.hideLoading();
            // 这里此提示会被this.start()方法中的提示覆盖
            uni.$u.toast('验证码已发送');
            // 通知验证码组件内部开始倒计时
            this.$refs.uCode.start();
          }, 2000);
        } else {
          uni.$u.toast('倒计时结束后再发送');
        }
      },
      change(e) {
        console.log('change', e);
      }
    }
  }
</script>
相关文章
|
移动开发 小程序 JavaScript
uniapp中uview组件库的Input 输入框 的使用方法
uniapp中uview组件库的Input 输入框 的使用方法
2159 0
|
小程序 API
uniapp中uview组件库丰富的Calendar 日历用法
uniapp中uview组件库丰富的Calendar 日历用法
1740 0
|
存储 Docker 容器
在 Docker 中部署 Mino 并挂载配置文件
在 Docker 中部署 Mino 并挂载配置文件
|
关系型数据库 MySQL 数据安全/隐私保护
在 Docker 中部署 Mysql 并挂载配置文件
在 Docker 中部署 Mysql 并挂载配置文件
|
前端开发 算法 JavaScript
React项目input输入框输入自动失去焦点
本文讨论了在React项目中如何处理input输入框自动失去焦点的问题,特别是在移动端开发中。文章提供了一个使用React Native的TouchableWithoutFeedback组件来监听点击事件,并在事件处理函数中通过调用Keyboard.dismiss()方法使输入框失去焦点的示例代码。这种方法可以确保在用户点击页面其他区域时,键盘能够收起,输入框失去焦点。
465 1
React项目input输入框输入自动失去焦点
|
前端开发 容器
前端技术分享:利用CSS Grid布局实现响应式设计
【10月更文挑战第1天】前端技术分享:利用CSS Grid布局实现响应式设计
|
定位技术 API
高德地图web服务API接口开发:获取IP定位显示当前位置的天气预报解决方案
高德地图web服务API接口开发:获取IP定位显示当前位置的天气预报解决方案
765 0
|
SQL 存储 安全
SQL安全性能:构建坚不可摧的数据防线
随着信息技术的发展,数据成为核心资产,SQL数据库作为关键工具,其安全性至关重要。本文探讨了SQL安全的重要性、常见威胁及对策: - **重要性**: 包括数据保护、业务连续性和合规要求。 - **威胁**: 如SQL注入、未经授权访问、数据泄露和拒绝服务攻击。 - **措施**: 实施访问控制、数据加密、定期更新/备份、审计/监控及漏洞管理。 - **最佳实践**: 定期培训、建立应急响应计划、持续评估改进和安全编程。 通过这些方法,组织能够构建强大的SQL数据防护体系。
558 0
|
IDE Java 测试技术
Springboot单元测试步骤
Springboot单元测试步骤
385 0
|
PHP
php 使用phpize报错Cannot find config.m4. Make sure that you run ‘/usr/bin/phpize‘ in the top l
php 使用phpize报错Cannot find config.m4. Make sure that you run ‘/usr/bin/phpize‘ in the top l
708 1