| | |
| | | <view class="main"> |
| | | <view class="inner1">{{desc}}</view> |
| | | <view class="put inner2"> |
| | | <input class="p-input" type="text" :placeholder="placeholder" @input="input" v-model="val"> |
| | | <uni-icons class="p-icon" type="closeempty" size="16" color="#707070" v-show="val.length" @click="clear"></uni-icons> |
| | | <input class="p-input" type="text" :placeholder="placeholder" v-model="data" :focus="focusData"> |
| | | <uni-icons class="p-icon" type="closeempty" size="16" color="#707070" |
| | | v-show="data.length" @click="clear"> |
| | | </uni-icons> |
| | | </view> |
| | | <view class="inner3" v-show="btn"> |
| | | <button class="m-btn" size="mini">{{btnName}}</button> |
| | | <button class="m-btn" size="mini" @click="clickBtn">{{btnName}}</button> |
| | | </view> |
| | | </view> |
| | | </view> |
| | |
| | | <script> |
| | | export default { |
| | | name:"z-input", |
| | | data() { |
| | | return { |
| | | data:'', |
| | | focusData: false |
| | | }; |
| | | }, |
| | | props: { |
| | | desc: { |
| | | type: String, |
| | |
| | | default: '请输入' |
| | | }, |
| | | value: { |
| | | type: String, |
| | | type: [String,Number], |
| | | default: '' |
| | | }, |
| | | lenCheck: { |
| | | type: [Number], |
| | | default: null |
| | | }, |
| | | focus: { |
| | | type: Boolean, |
| | | default: false |
| | | } |
| | | }, |
| | | watch: { |
| | | value(val) { |
| | | console.log(1); |
| | | this.val = val |
| | | data(val) { |
| | | if (!this.lenCheck) { |
| | | this.$emit('input',val) |
| | | return |
| | | } |
| | | if (val.length != this.lenCheck) { |
| | | setTimeout(()=>{ |
| | | this.data = '' |
| | | this.$emit('input','') |
| | | },10) |
| | | } else { |
| | | this.$emit('input',val) |
| | | } |
| | | }, |
| | | focus(f) { |
| | | console.log(f); |
| | | this.focusData = !f |
| | | setTimeout(()=>{ |
| | | this.focusData = f |
| | | },10) |
| | | } |
| | | }, |
| | | created() { |
| | | this.val = this.value |
| | | }, |
| | | data() { |
| | | return { |
| | | val:'', |
| | | }; |
| | | this.data = this.value |
| | | this.focusData = this.focus |
| | | }, |
| | | methods: { |
| | | input() { |
| | | console.log(3); |
| | | if(this.val.length != this.lenCheck) { |
| | | this.val = '' |
| | | } |
| | | this.$emit('input',this.val); |
| | | }, |
| | | clear() { |
| | | this.val = '' |
| | | this.input() |
| | | this.data = '' |
| | | }, |
| | | clickBtn() { |
| | | this.$emit('clickBtn'); |
| | | } |
| | | } |
| | | } |