My props with vue.js pass me the value as undefined

1

I'm using vue.js to make a query with a value from a view but when I pass the value of the props I get the impression of the console as "undefined" because of that I can not make any query for the undefined value you send this is the code I am using:

import ApiCanal10 from '../lib/api-canal10'

export default {
  props: ['idVideo'],
  data: () => ({
    videos: []
  }),
  created() {
    //do something after creating vue instance
    this.api = new ApiCanal10({})
    this.getRelVideos()

  },
  methods: {
    getRelVideos: function() {
      //este es lo que se envia la consola
      console.log('video/related/${this.idVideo}')
    }
  }
}

Due to the indefinite can not do the queries that are needed to show the information.

    
asked by JULIO MACHAN 28.10.2017 в 21:47
source

1 answer

0

I did a quick test with several elements of your code and it works for me without a problem, maybe you are wrongly defining the parameter when you call the component? Note the camel-case syntax as it works: <child id-video="hola amigos!"></child>

Vue.component('child', {

  props: ['idVideo'],
  template: '<span>{{ idVideo }}</span>',
  created() {
    this.getRelVideos()
  },
  methods: {
    getRelVideos() {
      //este es lo que se envia la consola
      console.log('video/related/${this.idVideo}')
    }
  }
  
})

new Vue({
  el: '#app'
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.2/vue.min.js"></script>
<div id="app">
  <child id-video="hola amigos!"></child>
</div>
    
answered by 28.10.2017 в 22:01