HTML side
<div id="string"> <ul> <li v-for="array in sortArrays(arrays)">{{ array.name }}</li> </ul> </div>
Vue JS code || Using Lodash
var string = new Vue({ el: '#string', data: { arrays: [ { name: 'kano', sex: 'man' }, { name: 'striker', sex: 'man' }, { name: 'sonya', sex: 'woman' }, { name: 'sindell', sex: 'woman' }, { name: 'subzero', sex: 'man' } ] }, methods: { sortArrays(arrays) { return _.orderBy(arrays, 'name', 'asc'); } } })
- in the orderBy function, the first argument is an array, the second argument is the key (name / gender), the third argument is order (asc / desc)
Rayees pk
source share