0

I have a vue component and it pass the string to nested vue component as follow,

<products-by-category :category="this.value"></products-by-category>

following section shows how I try to use that passed string in that nested vue component. but it is not getting that string to <span>. what is the wrong with it??

<template>
  <span>Category : {{ categories }}</span>
</template>

<script>
export default {
name: "ProductsByCategory",
  props: {
  category: {
    type: String,
    default: function (){
      return ''
    }
  }
  },

  data(){
   return {
     categories: this.category
   }
  }
}
</script>

<style scoped>

</style>

1 Answer 1

0

I have resolved it as follows,

<template>
  <input type="text" v-model="category">
</template>

<script>
export default {
name: "ProductsByCategory",
  props: {
  category: {
    type: String,
  }
  }
}
</script>

<style scoped>

</style>

reference: How to access data from deeply nested child components in Vue.js

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.