[Vuejs]-How to get "this" to not be undefined from method in Vue?

2👍

When you reference this, it is refering to your vue component but in your Vue component you only define one data element, people: people. In order to make your method work, you need to send in a parameter to your method and use the passed parameter instead of this.

HTML: <a v-text="getAddress(person)"></a>

JS:

    getAddress(person) {
      return '' + person.address + '';
    }

But you could easily do this without needing the method at all with:

  <div v-for="person in people" class="box">
    <h1>{{person.name}}</h1>
    <a v-text="person.address"></a>
  </div>

Leave a comment