How can I create a list in laravel (v7) blade using the VueJS v-for method?
inside home.blade.php:
<template v-for="(item,index) in this.list">
<qm-item number="@{{index}}"></qm-item>
</template>
in the source code this results in:
<qm-item number="index"></qm-item>
but i would like to have number=0 or =1 on the first qm-item, number=2 on the second and so on.
UPDATE: the issue was how I was checking it, since the DOM is re-rendered I cannot check in the browser source code for this, because this won't be up to date.
3 Answers 3
You should bind
the number as follows:
<qm-item :number="index"></qm-item>
3 Comments
You need to bind number
:
<template v-for="(item,index) in this.list">
<qm-item :number="index"></qm-item>
</template>
index
will be defined on the Vue.js side, not on the Laravel side.
1 Comment
When you pass data from blade to your Vue component you have to bind the props with a leading :
So, in your case, it should be <qm-item :number="{{index}}"></qm-item>
Also, use variable just like you normally do in the blade.