homHeader.vue
3.49 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<template>
<div class="header">
<nav class="nav">
<ul>
<li class="on">
<router-link to="/">
首页
</router-link>
</li>
<li v-for="(item,index) in categoryList.slice(0, 6)" :key="index" @click="jumpCategory(item)">
{{item.classifyName}}
</li>
</ul>
</nav>
<div class="search">
<div class="searchSelect">
<el-dropdown @command="searchCommand" trigger="click">
<span class="el-dropdown-link">{{searchVal}}
<i class="el-icon-arrow-down cur-poi el-icon--right"></i>
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="宝贝">宝贝</el-dropdown-item>
<el-dropdown-item command="店铺">店铺</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
<div class="searchRight">
<input type="text"
v-model="keyword"
@keyup.enter="searchPro"
placeholder="请输入搜索商品"
>
</div>
<span class="btn cur-poi" @click="searchPro">
<i class="icon el-icon-search"></i>
</span>
</div>
</div>
</template>
<script>
import {
getCategory
} from '@/api/nav.js'
import { mapMutations } from 'vuex'
export default {
name: 'homHeader',
data () {
return {
searchVal: '宝贝',
keyword: '',
categoryList: []
}
},
mounted () {
this.getCategoryData()
},
methods: {
...mapMutations({
setSearchObj: 'SET_SEARCHOBJ'
}),
searchCommand (command) {
this.searchVal = command
},
// 查找
searchPro () {
this.setSearchObj({
keyword: this.keyword,
searchVal: this.searchVal
})
if (this.$route.name !== 'search') {
this.$router.push({
path: '/activity/search'
})
}
},
async getCategoryData () {
const response = await getCategory()
const res = response.data
if (res.code === '200') {
this.categoryList = res.data
}
},
// 跳转到类别主页
jumpCategory (item) {
this.$router.push({
name: 'category',
query: {
classifyData: JSON.stringify(item)
}
})
}
}
}
</script>
<style scoped lang="scss">
$lightBlack: #666666;
$navSearchHeight: 39px;
.header{
height: 80px;
width: 1200px;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: nowrap;
.nav{
float: left;
padding-top: 30px;
ul{
width: 760px;
display: flex;
justify-content: space-between;
}
li{
font-size: 16px;
line-height: 21px;
padding-bottom: 24px;
color: #333;
cursor: pointer;
border-bottom: 3px solid #fff;
&.on,&:hover{
color: #C5AA7B;
border-color: #C5AA7B;
}
}
}
.search{
width: 394px;
height: 39px;
border: 2px solid #F3F4F5;
float: right;
// margin-top: 21px;
display: flex;
.searchSelect{
width: 82px;
height: 30px;
margin-top: 2px;
border-right: 1px solid #CCCCCC;
text-align: center;
line-height: 30px;
.el-dropdown{
color: #C5AA7B;
}
}
.searchRight{
flex: 1;
input{
padding-left: 15px;
font-size: 14px;
color: #333;
line-height: 35px;
}
}
.btn{
font-size: 20px;
line-height: 35px;
padding-right: 15px;
}
}
}
</style>