Vue.Js in Reverse Array Using v-for OrderBy Filter Example

Vue.Js

Nicesnippets

1072

17-08-2020


Hi Guys

In this blog,I will explain you how to convert reverse array using v-for orderby filter in vue.js. We will show vue js in reverse array using v-for orderby filter example. i will use reverse method using array reverse in vue.js. you can easyliy convert array in reverse.

Here, I will give you full example for simply reverse array using v-for orderby filter in vue.js as bellow.

Script Code

<script>

Vue.config.devtools = true

var app = new Vue({

el:'.card-body',

data:{

items:[

{ message: 'Php' },

{ message: 'Laravel'},

{ message: 'Java'},

{ message: 'Html'},

],

},

filters: {

reverse(items) {

return items.slice().reverse()

}

}

});

</script>

Full Example

<!DOCTYPE html>

<html>

<head>

<title>Vue Js in Reverse Array Using v-for OrderBy Filter Example</title>

<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.0-alpha1/css/bootstrap.min.css">

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

</head>

<body class="bg-dark">

<div class="container">

<div class="col-md-7 offset-md-3">

<div class="card mt-5">

<div class="card-header">

<h5>Vue Js in Reverse Array Using v-for OrderBy Filter Example</h5>

</div>

<div class="card-body">

<div class="row">

<div class="col-md-12">

<ul>

<li v-for="item in items | reverse" v-text="item.message"></li>

</ul>

</div>

</div>

</div>

</div>

</div>

</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.18/vue.min.js"></script>

<script>

Vue.config.devtools = true

var app = new Vue({

el:'.card-body',

data:{

items:[

{ message: 'Php' },

{ message: 'Laravel'},

{ message: 'Java'},

{ message: 'Html'},

],

},

filters: {

reverse(items) {

return items.slice().reverse()

}

}

});

</script>

</body>

</html>

It will you...


Recommended Posts