forked from xuqiang521/nuxt-ssr-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.vue
110 lines (108 loc) · 2.13 KB
/
input.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<template>
<div
class="search-from"
:class="{
'focus': focused
}">
<input
v-model="currentValue"
class="search-input"
:type="type"
:placeholder="placeholder"
:maxlength="~~maxlength"
@keyup.enter="search"
@change="handleChange"
@input="handleInput"
@focus="handleFocus"
@blur="handleBlur">
<img v-show="type === 'search'" class="search-icon" :src="searchImg" alt="搜索">
</div>
</template>
<script>
export default {
name: 'VInput',
props: {
type: {
type: String,
default: 'search'
},
placeholder: {
type: String,
default: '搜索掘金'
},
maxlength: {
type: [Number, String],
default: 20
},
value: {
type: String,
default: ''
}
},
data () {
return {
currentValue: this.value,
focused: false,
searchImg: require('@/assets/img/search.svg')
}
},
watch: {
focused (val) {
if (val) {
this.searchImg = require('@/assets/img/active-search.svg')
} else {
this.searchImg = require('@/assets/img/search.svg')
}
}
},
methods: {
search () {
this.$emit('search', this.currentValue)
},
handleChange () {
this.$emit('change', this.currentValue)
},
handleInput () {
this.$emit('input', this.currentValue)
},
handleFocus (event) {
this.focused = true
this.$emit('focus', event)
},
handleBlur (event) {
this.focused = false
this.$emit('blur', event)
}
}
}
</script>
<style lang="stylus" scoped>
.search-from {
display flex
align-items center
-webkit-box-pack justify
-ms-flex-pack justify
justify-content space-between
border 1px solid hsla(0, 0%, 59%, .2)
border-radius 2px
background-color rgba(227, 231, 236, .2)
.search-input {
border none
width 10rem
padding .6rem 1rem
box-shadow none
outline none
font-size 1.1rem
color #666
background-color transparent
}
.search-icon {
padding 0 .5rem
cursor pointer
}
}
.search-from.focus {
background #fff
border 1px solid #007fff
}
</style>