3
3
<ca-search class =" search__input" v-model =" searchInput" ></ca-search >
4
4
<ca-data-table class =" search__result" >
5
5
<tbody >
6
- <tr v-for =' (resultItem, index) in searchResult' :key =' index' ><th >
7
- {{resultItem.name}}
8
- </th ></tr >
6
+ <tr v-for =' (resultItem, index) in searchResult' :key =' index' >
7
+ <th >
8
+ <router-link :to =" '/component/'+resultItem.name" >{{resultItem.name}}</router-link >
9
+ </th >
10
+ <th >
11
+ {{resultItem.content}}
12
+ </th >
13
+ </tr >
9
14
</tbody >
10
15
</ca-data-table >
11
16
</div >
@@ -19,7 +24,7 @@ export default {
19
24
name: ' search' ,
20
25
data : ()=> ({
21
26
searchInput: ' ' ,
22
- searchResult: [' Nothing matches ' , ],
27
+ searchResult: [],
23
28
fuse: null ,
24
29
options: {
25
30
matchAllTokens: true ,
@@ -44,14 +49,21 @@ export default {
44
49
},
45
50
mounted () {
46
51
// add focus event API to ca-search
47
- this .elementInput = document .querySelector (' .search__input' )
48
- this .elementResult = document .querySelector (' .search__result' )
49
- this .elementInput .addEventListener (' focus' ,this .toggleResult ,true )
50
- this .elementInput .addEventListener (' blur' ,this .toggleResult ,true )
52
+ if (typeof window !== ' undefined' ) {
53
+ this .elementInput = document .querySelector (' .search__input' )
54
+ this .elementResult = document .querySelector (' .search__result' )
55
+ this .elementInput .addEventListener (' focus' ,this .toggleResult ,true )
56
+ this .elementInput .addEventListener (' blur' ,this .toggleResult ,true )
57
+ }
51
58
},
52
59
methods: {
53
60
toggleResult () {
54
- this .elementResult .style .visibility = this .elementResult .style .visibility === ' visible' ? ' hidden' : ' visible'
61
+ // TODO: fix this ugly way
62
+ if (typeof window !== ' undefined' ) {
63
+ setTimeout (()=> {
64
+ this .elementResult .style .visibility = this .elementResult .style .visibility === ' visible' ? ' hidden' : ' visible'
65
+ },1000 )
66
+ }
55
67
},
56
68
},
57
69
}