How to work with Json on Vuejs?

Asked

Viewed 689 times

0

Look at the code:

Address table

Notice that the application is working perfectly, by clicking on any address it is automatically directed to the Google page because of this method right 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 it clicks on the record that has this specific email [email protected]

I tried that way, but I didn’t succeed:

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

How could I make this implementation?

  • Try: if (bancodedado.email === '[email protected]')

  • It doesn’t work and still gives an error in the console saying that the email variable is undefined.

  • 1

    It does. See: https://jsfiddle.net/4pcLfd7L/6/

  • Dude, it worked, I just copied and pasted the code, but I couldn’t find what was wrong before, thanks, thank you very much. :)

  • can post this solution as an answer. Thank you very much.

  • Because of the this, see the documentation - The Vue Instance

Show 1 more comment

1 answer

1


The problem occurs due to 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 an 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 example above an object is created with the property email and the method getPessoa that when executed the this inside is linked to the object person.

For better understanding, below links to reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.