[Vuejs]-Unable to access nested elements and to apply functions in Vue template?

0👍

data.telegram is undefined until your mounted method get a response from the server. I suggest you to replace your template code with a computed property that check if your data has value:

<template>
  <p>{{mydata}}</p>
  <p>{{telegramLen}}</p>
</template>

<script>
export default {
  computed: {
     mydata() {
        if (this.data != [])
           return this.data.telegram[0]
        return "No data"
     },
     telegramLen() {
        if (this.data.length > 0)
            return this.data.telegram.length
        return 0
     }
  }
}
</script>

Leave a comment