v-for Directive in Vue.js
Syntax:
v-for="data in datas"
Parameters: This function accepts data which is either an array or object over which we will loop over.
Example: This example uses Vue.js to loop over an array with v-for.
<!DOCTYPE html>
<html>
<head>
<title>
VueJS | v-for directive
</title>
<!-- Load Vuejs -->
<script src=
"https://cdn.jsdelivr.net/npm/vue/dist/vue.js">
</script>
</head>
<body>
<div style="text-align: center;
width: 600px;">
<h1 style="color: green;">
GeeksforGeeks
</h1>
<b>
VueJS | v-for directive
</b>
</div>
<div id="canvas" style=
"border:1px solid #000000;
width: 600px;height: 200px;">
<div id="app">
<h2 v-for="data in datas">
{{data}}
</h2>
</div>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
datas: [
'Hello',
'World',
'GeeksforGeeks'
]
}
})
</script>
</body>
</html>
Output:
