搜索导航栏

Header搜索组件:选择性CV

router/index.js
1
2
3
4
5
6
7
8
9
10
import SearchCourse from '../views/SearchCourse.vue'

const routes = [
// ...
{
path: '/course/search',
name: 'search-course',
component: SearchCourse,
},
];
Header.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
<form class="search">
<div class="tips" v-if="is_search_tip">
<span @click="search_action('Python')">Python</span>
<span @click="search_action('Linux')">Linux</span>
</div>
<input type="text" :placeholder="search_placeholder" @focus="on_search" @blur="off_search" v-model="search_word">
<button type="button" class="glyphicon glyphicon-search" @click="search_action(search_word)"></button>
</form>

<script>
export default {
data() {
return {
is_search_tip: true,
search_placeholder: '',
search_word: ''
}
},
methods: {
search_action(search_word) {
if (!search_word) {
this.$message('请输入要搜索的内容');
return
}
if (search_word !== this.$route.query.word) {
this.$router.push(`/course/search?word=${search_word}`);
}
this.search_word = '';
},
on_search() {
this.search_placeholder = '请输入想搜索的课程';
this.is_search_tip = false;
},
off_search() {
this.search_placeholder = '';
this.is_search_tip = true;
},
},
}
</script>

<style scoped>
.search {
float: right;
position: relative;
margin-top: 22px;
margin-right: 10px;
}

.search input, .search button {
border: none;
outline: none;
background-color: white;
}

.search input {
border-bottom: 1px solid #eeeeee;
}

.search input:focus {
border-bottom-color: orange;
}

.search input:focus + button {
color: orange;
}

.search .tips {
position: absolute;
bottom: 3px;
left: 0;
}

.search .tips span {
border-radius: 11px;
background-color: #eee;
line-height: 22px;
display: inline-block;
padding: 0 7px;
margin-right: 3px;
cursor: pointer;
color: #aaa;
font-size: 14px;

}

.search .tips span:hover {
color: orange;
}
</style>

posted on 2020-12-26 21:42  Plyc  阅读(129)  评论(0编辑  收藏  举报

导航