Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1dc1b21

Browse files
imple the search ui and logic partly
1 parent0c8caa0 commit1dc1b21

File tree

4 files changed

+106
-5
lines changed

4 files changed

+106
-5
lines changed

‎package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dependencies": {
1111
"babel-runtime":"^6.26.0",
1212
"carvue":"^0.1.4",
13+
"fuse.js":"^3.2.1",
1314
"github-markdown-css":"^2.10.0",
1415
"highlight.js":"^9.12.0",
1516
"install":"^0.12.1",

‎src/components/Search.vue

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<template>
2+
<divclass="search">
3+
<ca-searchclass="search__input"v-model="searchInput"></ca-search>
4+
<ca-data-tableclass="search__result">
5+
<tbody>
6+
<tr>
7+
<th>
8+
itemA
9+
</th>
10+
<th>
11+
itemB
12+
</th>
13+
</tr>
14+
<tr>
15+
<th>
16+
itemE
17+
</th>
18+
<th>
19+
itemD
20+
</th>
21+
</tr>
22+
</tbody>
23+
</ca-data-table>
24+
</div>
25+
</template>
26+
<script>
27+
/* eslint-disable*/
28+
importFusefrom'fuse.js'
29+
30+
exportdefault {
31+
name:'search',
32+
data: ()=> ({
33+
searchInput:'',
34+
fuse:null,
35+
// TODO: Generator Those data
36+
books: [{
37+
'ISBN':'A',
38+
'title':"Old Man's War",
39+
'author':'John Scalzi',
40+
}, {
41+
'ISBN':'B',
42+
'title':'The Lock Artist',
43+
'author':'Steve Hamilton',
44+
},
45+
],
46+
options: {
47+
keys: [{
48+
name:'title',
49+
weight:0.3
50+
}, {
51+
name:'author',
52+
weight:0.7
53+
}]
54+
},
55+
elementInput:null,
56+
elementResult:null,
57+
}),
58+
beforeMount() {
59+
this.fuse=newFuse(this.books,this.options)
60+
},
61+
mounted() {
62+
// add focus event API to ca-search
63+
this.elementInput=document.querySelector('.search__input');
64+
this.elementResult=document.querySelector('.search__result');
65+
this.elementInput.addEventListener('focus',this.toggleResult,true);
66+
this.elementInput.addEventListener('blur',this.toggleResult,true);
67+
},
68+
methods: {
69+
toggleResult() {
70+
this.elementResult.style.visibility=this.elementResult.style.visibility==='visible'?'hidden':'visible'
71+
},
72+
},
73+
watch: {
74+
searchInput:function(newValue) {
75+
console.log(this.fuse.search(newValue))
76+
}
77+
}
78+
}
79+
</script>
80+
81+
<style scroped>
82+
.search {
83+
margin:20px0;
84+
position:relative;
85+
}
86+
87+
/* TODO: remove important*/
88+
.search__result {
89+
position:absolute!important;
90+
padding:0!important;
91+
z-index:100;
92+
visibility:hidden;
93+
}
94+
</style>

‎src/components/SlideMenu.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<divclass="slideMenu">
33
<pclass="slideMenu__title">CarvueJS</p>
44
<pclass="slideMenu__subTitle">Carbon Design in VueJS</p>
5-
<ca-searchclass="slideMenu__search"></ca-search>
5+
<search></search>
66
<ca-accordion>
77
<divclass="slideMenu__item">GET STARTED</div>
88
<ca-accordion-itemtitle="Components"active>
@@ -16,8 +16,13 @@
1616
</template>
1717

1818
<script>
19+
importsearchfrom'./Search.vue'
20+
1921
exportdefault {
2022
name:'slideMenu',
23+
components: {
24+
search,
25+
},
2126
data: ()=> ({
2227
// TODO: generator the array automatically
2328
pages: [
@@ -41,10 +46,6 @@ export default {
4146
font-size:12px;
4247
}
4348
44-
.slideMenu__search {
45-
margin:20px0;
46-
}
47-
4849
.slideMenu__item {
4950
margin:10px7px;
5051
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp