|
@@ -5,7 +5,7 @@
|
|
|
<nut-icon type="search" v-if="hasIcon" :size="searchIconSize" :color="searchIconColor"></nut-icon>
|
|
<nut-icon type="search" v-if="hasIcon" :size="searchIconSize" :color="searchIconColor"></nut-icon>
|
|
|
<input
|
|
<input
|
|
|
type="search"
|
|
type="search"
|
|
|
- v-model="value"
|
|
|
|
|
|
|
+ :value="value"
|
|
|
:placeholder="placeText || nutTranslate('lang.searchbar.placeText')"
|
|
:placeholder="placeText || nutTranslate('lang.searchbar.placeText')"
|
|
|
@keyup.enter="submitFun"
|
|
@keyup.enter="submitFun"
|
|
|
@input="inputFun"
|
|
@input="inputFun"
|
|
@@ -80,6 +80,10 @@ export default {
|
|
|
customClass: {
|
|
customClass: {
|
|
|
type: String,
|
|
type: String,
|
|
|
default: ''
|
|
default: ''
|
|
|
|
|
+ },
|
|
|
|
|
+ value: {
|
|
|
|
|
+ type: String,
|
|
|
|
|
+ default: ''
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
components: {
|
|
components: {
|
|
@@ -87,32 +91,44 @@ export default {
|
|
|
},
|
|
},
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
- value: '', //输入值
|
|
|
|
|
- hasCloseIcon: false,
|
|
|
|
|
inputFocusAnimation: false
|
|
inputFocusAnimation: false
|
|
|
};
|
|
};
|
|
|
},
|
|
},
|
|
|
- computed: {},
|
|
|
|
|
|
|
+ watch: {
|
|
|
|
|
+ value(newValue, oldValue) {
|
|
|
|
|
+ this.updateValue('change');
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ computed: {
|
|
|
|
|
+ hasCloseIcon() {
|
|
|
|
|
+ return this.value ? true : false;
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ mounted() {},
|
|
|
methods: {
|
|
methods: {
|
|
|
|
|
+ updateValue(trigger = 'input') {
|
|
|
|
|
+ let searchInputValue = trigger == 'change' ? this.value : this.$refs.searchInput.value;
|
|
|
|
|
+ console.log(searchInputValue);
|
|
|
|
|
+ this.$emit(trigger, searchInputValue);
|
|
|
|
|
+ },
|
|
|
//清空 input 输入
|
|
//清空 input 输入
|
|
|
clearInput() {
|
|
clearInput() {
|
|
|
- this.value = '';
|
|
|
|
|
- this.hasCloseIcon = false;
|
|
|
|
|
|
|
+ this.$emit('clear', '');
|
|
|
|
|
+ this.$emit('input', '');
|
|
|
},
|
|
},
|
|
|
focusFun() {
|
|
focusFun() {
|
|
|
this.inputFocusAnimation = true;
|
|
this.inputFocusAnimation = true;
|
|
|
this.$emit('focus');
|
|
this.$emit('focus');
|
|
|
},
|
|
},
|
|
|
inputFun() {
|
|
inputFun() {
|
|
|
- this.hasCloseIcon = this.value ? true : false;
|
|
|
|
|
- this.$emit('input', this.value);
|
|
|
|
|
|
|
+ this.updateValue();
|
|
|
},
|
|
},
|
|
|
blurFun() {
|
|
blurFun() {
|
|
|
this.inputFocusAnimation = false;
|
|
this.inputFocusAnimation = false;
|
|
|
- this.$emit('blur', this.value);
|
|
|
|
|
|
|
+ this.updateValue('blur');
|
|
|
},
|
|
},
|
|
|
submitFun() {
|
|
submitFun() {
|
|
|
- this.$emit('submit', this.value);
|
|
|
|
|
|
|
+ this.updateValue('submit');
|
|
|
},
|
|
},
|
|
|
// 失去焦点
|
|
// 失去焦点
|
|
|
blur() {
|
|
blur() {
|