Skip to content

Commit aca9a7c

Browse files
author
Vinayak Kulkarni
committed
Updated README
1 parent f48e3fd commit aca9a7c

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

README.md

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,64 +31,56 @@ import sort from 'vuejs-sort';
3131
## :white_check_mark: Example :four_leaf_clover:
3232

3333
```html
34-
<sort :data="sortingData" label="Name" icon="chevron" v-on:sort-data="sortData"></sort>
34+
<sort label="Posts (asc)" icon="chevron" :toRoute="{ name: 'somewhere.index', query: { sort : 1, sorttype: 'asc' }}" @sort-data="sortData" v-if="sorttype === 'desc'"></sort>
35+
<sort label="Posts (desc)" icon="chevron" :toRoute="{ name: 'somewhere.index', query: { sort : 1, sorttype: 'asc' }}" @sort-data="sortData" v-if="sorttype === 'asc'"></sort>
3536
```
3637

3738
```javascript
3839
Vue.component('example-component', {
3940

4041
data() {
4142
return {
42-
// Our data object that holds the Sorting data
43-
sortingData: {},
43+
// You could have $route.query.sort or set a custom value as per your backend
44+
// sort: Number(this.$route.query.sort),
45+
sort: 1,
46+
sorttype: 'asc',
4447
}
4548
},
4649

47-
created() {
48-
// Fetch initial results
49-
this.sortData();
50-
},
51-
5250
methods: {
53-
// Our method to GET results from a Laravel endpoint
5451
sortData(sort, direction) {
55-
if (typeof sort === 'undefined') {
56-
sort = 1;
57-
}
58-
52+
this.sort = sort;
53+
this.sorttype = direction;
54+
this.filterData();
55+
},
56+
// Our method to GET results from a Laravel endpoint
57+
filterData() {
5958
// Using vue-resource as an example
60-
this.$http.get('example/results?sort=' + page + '&direction=' + direction)
59+
t.$http.get('/api/v1/posts?sort=' + t.sort + '&sorttype=' + t.sorttype)
6160
.then(response => {
62-
return response.json();
63-
}).then(data => {
64-
this.sortingData = data;
61+
// do whatever you do with response data
62+
}).catch(error => {
63+
// do whatever you do with error data
6564
});
6665
}
6766
}
6867

6968
});
7069
```
7170

72-
### :white_check_mark: :book: Props
71+
### :white_check_mark: Props :book:
7372

7473
| Name | Type | Description |
7574
| --- | --- | --- |
76-
| `data` | Object | An object containing `sort` (you can set this at your backend) & `sorttype` (viz. Direction eg. `'asc'`, `'desc'`) |
7775
| `icon` | String | (optional) Default is `chevron`; Refer [Semantic-UI Icons](https://semantic-ui.com/elements/icon.html) for specifying which icons you want. |
7876
| `label` | String | (optional) Is responsible for the label that'll be displayed which will be clickable. |
77+
| `toRoute` | Object | An object containing `name` (viz. Route Name) & `query` (viz. a object containing `sort` & `sorttype` similar to `$route.query`) |
7978

80-
```javascript
81-
{
82-
sort: 1,
83-
sorttype: 'asc',
84-
}
85-
```
86-
87-
### :white_check_mark: :ear: Events
79+
### :white_check_mark: Events :ear:
8880

8981
| Name | Description |
9082
| --- | --- |
91-
| `sort-data` | Triggered when a user changes `sort` & `sorttype`.|
83+
| `sort-data` | Emits `sort` & `sorttype`.|
9284

9385

9486
## NPM :octocat:

0 commit comments

Comments
 (0)