码迷,mamicode.com
首页 > 其他好文 > 详细

搜索导航栏

时间:2020-12-31 12:25:08      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:poi   code   python   otto   输入   tip   plain   pad   keyword   

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>

搜索导航栏

标签:poi   code   python   otto   输入   tip   plain   pad   keyword   

原文地址:https://www.cnblogs.com/plyc/p/14194307.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!