vue-orderby-mixin
Version:
Sort a array object with a custom field
44 lines (38 loc) • 717 B
Markdown
Sort a array object with a custom field
``` bash
$ npm install vue-orderby-mixin
```
```javascript
this.orderBy(obj, column, type)
obj => Array object
column => A custom field for sorting
type => ASC or DESC
```
```javascript
import orderBy from 'vue-orderby-mixin'
export default {
data () {
return {
users: [
{ id: 1, name: 'John' },
{ id: 2, name: 'Jane' }
],
}
},
mixins: { orderBy },
methods: {
example () {
this.orderBy(this.users, 'name', 'ASC')
}
}
}
```
| id | name |
|----|------|
| 2 | Jane |
| 1 | John |