How to work with Json on VueJs?

0

Note the code:

Address Book

Notice that the application is working perfectly, by clicking on any address it is automatically directed to the Google page because of that method just below;

methods: {
    showLink: function(bancodedado) {
        window.open('http://www.google.com/?q=');

    }
},

What I want to do is to only be directed to the Google page when he clicks the record that has this specific email [email protected]

I tried it that way, but I was not successful:

methods: {
        showLink: function(bancodedado) {
            if (this.bancodedado.email == '[email protected]') {
            window.open('http://www.google.com/?q=');
            }
        }

How could I do this implementation?

    
asked by anonymous 20.02.2018 / 11:51

1 answer

1

The problem occurs because of the use of this , remember that in the context of global execution (Window and or Document), this refers to the global object and when you create a instance of Vue, an object is created with the properties and methods to be used by the instance.

var nome = 'Uma pessoa qualquer',
    idade = 349;

function getPessoa() {
  console.log(this.nome, this.idade);
}
getPessoa();

Method of an object

var nome = 'Uma pessoa qualquer',
  idade = 349;

function getPessoa() {
  console.log(this.nome, this.idade);
}
getPessoa();

var pessoa = {
  email: '[email protected]',
  getPessoa: function() {
    console.log(this.nome, this.idade, this.email);
    // undefined
    // undefined
    // [email protected]
  }
}
pessoa.getPessoa();

Note that in the above example an object with the email property and the getPessoa method is created, that when run in this is bound to person object.

For a better understanding, please see below links for reference.

20.02.2018 / 12:58