[Vuejs]-How can i print the component's id of Vue.js

0👍

Firstly, you need to actually provide the id to the <li is="todo-item" ... >s, which isn’t being done. You need to add v-bind:id="todo.id".

That being said, if you’re trying to print it from any of the Vue instance lifecycle hooks, then it’s as easy as console.log(this.id). For example:

Vue.component('todo-item', {
  ...
  mounted(){
    console.log(this.id)
  }
}

P.S. don’t use jQuery! Using jQuery with Vue is a code-smell. Here’s a pretty informational rant by Gitlab on why that is (plus more).

Leave a comment