Skip to content

Input

This component is an input box. It has no similar style by default. It is specially designed to cooperate with the form component wu-form. It can be used to quickly implement form validation and input content , drop-down selection and other functions.

You should implement wu-form-item in wu-form, and then wu-input to implement.

platform compatibility

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

Basic usage

  • Set the input box type by type, the default is text
  • Set the placeholder when the input box is empty by placeholder
  • Configure whether to display the border of the input box through border
  • Binding @change event
vue
<template>
  <wu-input
    placeholder="Please enter content"
    border="surround"
    v-model="value"
    @change="change"
  ></wu-input>
</template>

<script>
export default {
  data() {
    return {
      value: "",
    };
  },
  methods: {
    change(e) {
      console.log("change", e);
    },
  },
};
</script>
<template>
  <wu-input
    placeholder="Please enter content"
    border="surround"
    v-model="value"
    @change="change"
  ></wu-input>
</template>

<script>
export default {
  data() {
    return {
      value: "",
    };
  },
  methods: {
    change(e) {
      console.log("change", e);
    },
  },
};
</script>

Type of input box

Summary: The type of input box can be set by configuring type:

  1. text- text input keyboard.
  2. number-Number input keyboard, floating point numbers can be input under app-vue, and only integers can be input under app-nvue and applet platforms.
  3. idcard- ID card input keyboard, WeChat, Alipay, Baidu, QQ applet.
  4. digit- Numeric keyboard with decimal point, App's nvue page, WeChat, Alipay, Baidu, Toutiao, QQ applet.
  5. password-equivalent to setting password to true

Empty characters

Setting clearable to true will add a clear button behind the input field.

vue
<template>
  <wu-input placeholder="Please enter content" border="surround" clearable></wu-input>
</template>
<template>
  <wu-input placeholder="Please enter content" border="surround" clearable></wu-input>
</template>

underscore

By setting the attribute border to bottom it becomes an underline

vue
<template>
  <wu-input placeholder="Please enter content" border="bottom" clearable></wu-input>
</template>
<template>
  <wu-input placeholder="Please enter content" border="bottom" clearable></wu-input>
</template>

before and after icons

  • All rear icons can freely set style information. Setting clearable to true will add a clear button behind the input field.
vue
<template>
    <wu-input
        placeholder="front icon"
        prefixIcon="search"
        prefixIconStyle="font-size: 22px;color: #909399"
    ></wu-input>
    <wu-input
        placeholder="post icon"
        suffixIcon="map-fill"
        suffixIconStyle="color: #909399"
    ></wu-input>
</template>
<template>
    <wu-input
        placeholder="front icon"
        prefixIcon="search"
        prefixIconStyle="font-size: 22px;color: #909399"
    ></wu-input>
    <wu-input
        placeholder="post icon"
        suffixIcon="map-fill"
        suffixIconStyle="color: #909399"
    ></wu-input>
</template>

front and rear slots

Specify front and rear slots by setting slot to prefix or suffix

vue
<template>
	<view class="wu-demo-block">
		<text class="wu-demo-block__title">front and rear slots</text>
		<view class="wu-demo-block__content">
			<wu-input placeholder="front slot">
                <template #prefix>
                    <wu-text
                        text="http://"
                        slot="prefix"
                        margin="0 3px 0 0"
                        type="tips"
				    ></wu-text>
                </template>
			</wu-input>
		</view>
		<view
			class="wu-demo-block__content"
			style="margin-top: 15px;"
		>
			<wu-input placeholder="rear slot">
				<template #suffix>
					<wu-code
						ref="wuCode"
						@change="codeChange"
						seconds="20"
						changeText="X seconds to reacquire hahaha"
					></wu-code>
					<wu-button
						@tap="getCode"
						:text="tips"
						type="success"
						size="mini"
					></wu-button>
				</template>
			</u-input>
		</view>
	</view>
</template>

<script>
    // This is the import method without using the extended configuration. After using the extended configuration, you can directly use uni.$w.toast to charge the import
    import { toast } from '@/uni_modules/wu-ui-tools/libs/function/index.js';
    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.wuCode.canGetCode) {
                    // Simulate requesting a verification code from the backend
                    uni.showLoading({
                        title: 'Getting verification code'
                    })
                    setTimeout(() => {
                        uni.hideLoading();
                        // Here this prompt will be overridden by the prompt in this.start() method
                        toast('Verification code sent');
                        // Notify the internal countdown of the captcha component
                        this.$refs.wuCode.start();
                    }, 2000);
                } else {
                    toast('Send after countdown');
                }
            },
            change(e) {
                console.log('change', e);
            }
        }
    }
</script>
<template>
	<view class="wu-demo-block">
		<text class="wu-demo-block__title">front and rear slots</text>
		<view class="wu-demo-block__content">
			<wu-input placeholder="front slot">
                <template #prefix>
                    <wu-text
                        text="http://"
                        slot="prefix"
                        margin="0 3px 0 0"
                        type="tips"
				    ></wu-text>
                </template>
			</wu-input>
		</view>
		<view
			class="wu-demo-block__content"
			style="margin-top: 15px;"
		>
			<wu-input placeholder="rear slot">
				<template #suffix>
					<wu-code
						ref="wuCode"
						@change="codeChange"
						seconds="20"
						changeText="X seconds to reacquire hahaha"
					></wu-code>
					<wu-button
						@tap="getCode"
						:text="tips"
						type="success"
						size="mini"
					></wu-button>
				</template>
			</u-input>
		</view>
	</view>
</template>

<script>
    // This is the import method without using the extended configuration. After using the extended configuration, you can directly use uni.$w.toast to charge the import
    import { toast } from '@/uni_modules/wu-ui-tools/libs/function/index.js';
    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.wuCode.canGetCode) {
                    // Simulate requesting a verification code from the backend
                    uni.showLoading({
                        title: 'Getting verification code'
                    })
                    setTimeout(() => {
                        uni.hideLoading();
                        // Here this prompt will be overridden by the prompt in this.start() method
                        toast('Verification code sent');
                        // Notify the internal countdown of the captcha component
                        this.$refs.wuCode.start();
                    }, 2000);
                } else {
                    toast('Send after countdown');
                }
            },
            change(e) {
                console.log('change', e);
            }
        }
    }
</script>

API

Input Props

property namedescriptiontypedefault valueoptional values ​​
value / modelValueinput valueNumber / String--
typeinput box type, see above descriptionStringtextnumber / idcard / digit / password
disabledWhether to disable the input boxBooleanfalsetrue
disabledColorbackground color in disabled stateString#f5f7fa-
clearableWhether to display the clear controlBooleanfalsetrue
passwordpassword typeBooleanfalsetrue
maxlengthThe maximum input length, when set to -1, there is no limit to the maximum lengthString / Number-1-
placeholderplaceholder when the input box is emptyString--
placeholderClassSpecifies the style class of the placeholder. Note that when scoped is written in the style of the page or component, you need to write /deep/ before the class nameStringinput-placeholder-
placeholderStyleSpecifies the style of the placeholder, in the form of a string/object, such as "color: red;"String / Objectcolor: #c0c4cc-
showWordLimitWhether to display input word count statistics, only valid when type = "text" or type = "textarea"Booleanfalsetrue
confirmTypeSet the text of the button in the lower right corner, see uni-app documentation for compatibilityStringdonesend / search / next / go / done
confirmHoldWhether to keep the keyboard closed when the button on the bottom right corner of the keyboard is clicked, H5 is invalidBooleanfalsetrue
holdKeyboardWhen in focus, the keyboard will not be put away when the page is clicked, and the WeChat applet is validBooleanfalsetrue
focusGet the focus automatically. Whether it can be focused on the H5 platform and whether the soft keyboard pops up depends on the implementation of the current browser itself. The nvue page does not support it, you need to use the focus() and blur() methods of the component to control the focusBooleanfalsetrue
autoBlurWhether to automatically lose focus when the keyboard is closed, currently only valid for App3.0.0+Booleanfalsetrue
ignoreCompositionEventWhether to ignore the processing of text composition system events within the component. When false, compositionstart, compositionend, compositionupdate events will be fired, and input event will be fired during text compositionBooleantruefalse
disableDefaultPaddingWhether to remove the default padding under iOS, only valid for WeChat applets and type=textareaBooleanfalsetrue
cursorcursor position when focus is specifiedString / Number-1-
cursorSpacingThe distance between the bottom of the input box and the keyboard when it is focusedString / Number30-
selectionStartCursor start position, valid when auto-gathering, must be used together with selection-endString / Number-1-
selectionEndThe end position of the cursor, valid during automatic aggregation, and must be used in conjunction with selection-startString / Number-1-
adjustPositionWhether to automatically push up the page when the keyboard pops upBooleantruefalse
inputAlignAlignment of input box contentStringleftleft / center / right
fontSizeThe font size of the input boxString--
placeholderplaceholder when the input box is emptyString / Number15px-
colorinput box font colorString#303133-
prefixIconinput box prefix iconString--
prefixIconStyleprefix icon style, object or stringString / Object--
suffixIconinput box suffix iconString--
suffixIconStylesuffix icon style, object or stringString / Object--
borderborder type, surround-surround border, bottom-bottom border, none-no borderStringsurroundbottom / none
readonlyWhether it is read-only, the difference from disabled is that disabled will gray out the component, while readonly will notBooleanfalsetrue
shapeinput box shape, circle-circle, square-squareStringsquarecircle
formatterInput filtering or formatting function (if compatible with WeChat applet, only through the setFormatter method)Functionnull-
customStyleDefine the external style that needs to be usedObject--

Input Events

Event NameDescriptionCallback Parameters
blurtriggered when the input box loses focusvalue: content value
focusTriggered when the input box is focused-
confirmtriggered when the button is clickedvalue: content value
keyboardheightchangeThis event is triggered when the keyboard height changes-
inputThis event is triggered when the content changesvalue: content value
changeThis event is triggered when the content changesvalue: content value
clearClick to clear content-

Input Methods

method namedescription
setFormatterThe internal method exposed for compatibility with WeChat applets, see the description above

Input Slots

Slot NameDescription
prefixfront content of input box
suffixcontent after the input box