13

I can't figure out how to do a console.log to see what item is in the ul as its being passed.

 <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
        ]
    }
 })
3
  • it should just display, you should just look at what HTML the template is outputting, I think console logging would be a bit of overkill here Commented Jan 7, 2019 at 16:01
  • i guess i need for future endeavors as well, i need to know how to do it Commented Jan 7, 2019 at 16:04
  • a similar question: stackoverflow.com/questions/51080447/… Commented Aug 9, 2023 at 7:28

3 Answers 3

24

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)
    }
  }
})
Sign up to request clarification or add additional context in comments.

1 Comment

to use globally, add Vue.prototype.log = console.log; in main.js
7

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;
    }
 })

Comments

1

Similar to Daniel's answer, but you can simply reference console in data object

data(){
  return {
  console, //ES6
  ...
  }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.