How can I pass a parameter from an API query to vue-head?

0

I'm passing the value of a query using the vue-head for the browser title but when I pass the data does not pass any data in the header just send me a message like "undefined" at the top of the browser, this is the code:

    export default {
      data: () => ({
        video: {}
      }),
      methods: {
        getVideo() {
          this.api.http.get('videos/${this.videoSlug}')
            .then(response => {
              this.video = response['data'][0]
            })
        }
      },
  head: {
    title: function() {
      return {
        inner: this.video.name,
        separator: '|',
        complement: 'Canal 10'
      };
    }
  }
}

When I pass the value in this way it sends me with "undefined" but if I pass any data in a static way such as " inner: 'Magazine' " shows it in the browser, some idea of How can I solve this situation?

    
asked by JULIO MACHAN 24.10.2017 в 00:06
source

1 answer

1

I find some inconsistencies in your code (I hope you have not omitted / deleted it to ask the question).

First videoSlug is not defined in the data, and finally you need to add a console.log(response) so you can see what the structure of the response response is to your request.

Additionally, you could improve your code by avoiding that undesirable undefined by adding this inner = this.video.name ? this.video.name : 'Titulo por defecto aquí';

    
answered by 27.10.2017 в 23:20