Obtain data from a controller in Laravel in Vue Js and interact with them.

0

I'm trying to bring data from a Laravel driver to Vue JS.

   data() {
    return {
        article: undefined
    }
    },
    created() {
    this.$http.get('article/' + this.$route.params.id +  '/edit?include=category,tags')
        .then((response) => {
            this.article = response.data.data
        })
       },

The issue is that I do not want to get that data to show it in the view, I want to have that data to interact with them in the same method. More specifically, to make a layer in Leatfet of markers with the latitude and longitude fields of the Articles table.

       method(){
       getcapas(){
       //Código Leatfet
       var articles = this.$http.get('article/' + this.$route.params.id +  '/edit?include=category,tags')
        .then((response) => {
            return response.data.data
        })
        }

        //Código Leatfet con los datos de la tabla articles

When I make a console.log of the articles variable, I get the following:

Promise
[[PromiseStatus]]...
[[PromiseValue]]= array(4) /*Con todos los valores que necesito. 

How could I get the data from [[PromiseValue]] in the same method?

I've been investigating but I have not found a way to get that data and I have not found anything.

    
asked by Miguel Herreros Cejas 15.05.2018 в 09:33
source

2 answers

1

Try this:

created() {
    var article;
    this.$http.get('article/' + this.$route.params.id +  '/edit?include=category,tags')
        .then((response) => {
            article = response.data.data
        });
    console.log(article);

},

Trying to assign this.article within get will not access the properties of your data, so I create a variable in the same scope as the get and assign it the value within then

    
answered by 15.05.2018 в 15:37
0

In the end I chose to paint the markers within the promise, although I do not think it is very good practice.

    this.$http.get('articlesmap')
    .then((response) => {
      var articles = response.data.data


      articles.forEach((feature) => {
      console.log(feature);
      var coords = [feature.longitude,feature.latitude]
      L.marker(coords).bindPopup("<a href='http://localhost:8000/articles/"+feature.slug+"'>"+feature.title+"</a>").addTo(map);
      });

    });
    
answered by 29.05.2018 в 12:36