How to console.log an item inside a v-for loop in Vue
you should define a method like :
<ul v-if="item" :load="log(item)">
in your script :
var vm = new Vue({
el: '#components-demo',
data: {
todos: [
newData
]
},
methods: {
log(item) {
console.log(item)
}
}
})
I usually wrap the value I'm debugging in <pre>{{ myData }}</pre>
like this:
<div v-for="(item, index) in todos" :key="index">
<pre>{{ item }}</pre>
<ul v-if="item" :load="item">
<li v-for="(value, key) in item" :key="key">
<label v-bind:for="key">{{ key }}</label>
<div v-bind:id="key">{{ value }}</div>
</li>
</ul>
</div>
But you can also use console if you pass it into t he template context during create
<div v-for="(item, index) in todos" :key="index">
<ul v-if="item" :load="console.log(item)">
<li v-for="(value, key) in item" :key="key">
<label v-bind:for="key">{{ key }}</label>
<div v-bind:id="key">{{ value }}</div>
</li>
</ul>
</div>
var vm = new Vue({
el: '#components-demo',
data: {
todos: [
newData
]
},
created() {
this.console = window.console;
}
})