While developing my app I have had a wrapper (simplified for this example) which is the root of all my elements in the site. However I needed to include a component with custom properties alongside this wrapper. That's when I found that the properties on that component were never being read in.

index.html

<body>
  <div id="app" >  <!-- Vuejs is bound to this element -->
    <test-item testProp="My Test Prop Outside Wrapper"></test-item>
    <wrapper></wrapper>
  </div>
</body>

TestItem.vue

<template>
  <h1>{{ testProp }}</h1>
</template>

<script>
export default {
  props: {
    testProp: {
      type: String,
      default: "Default String"
    }
  }
}
</script>

Wrapper.vue

<template>
  <div>
    <test-item testProp="My Test Prop Inside Wrapper"></test-item>
  </div>
</template>

<script>
export default {

}
</script>

For reference where I import these components and init the Vue instance:

Vue.component('test-item', require('./components/TestItem.vue'));
Vue.component('wrapper', require('./components/Wrapper.vue'));

const app = new Vue({
  el: '#app'
});        

I would have expected since I am passing in testProp on both instances that the output would look like

<h1>My Test Prop Outside Wrapper</h1>
<div>
  <h1>My Test Prop Inside Wrapper</h1>
</div>

However, this is not what I am seeing, on the one outside the wrapper, the property is not passed through and the default property value is used

<h1>Default String</h1>
<div>
  <h1>My Test Prop Inside Wrapper</h1>
</div>

Any ideas what is going on?

share|improve this question
1  
Props on element must be written in kebab-case vuejs.org/v2/guide/components.html#camelCase-vs-kebab-case So component attribute should be test-prop="value here" – Belmin Bedak Jan 22 at 12:01
    
@BelminBedak how I didn't notice that I have no idea. Thankyou very much. Can you stick this up as an answer instead of a comment? – Jon Taylor Jan 22 at 12:05
up vote 1 down vote accepted

HTML attributes are case-sensitive so when you want to send prop, the atrribute of prop should be written in kebab-case instead of camelCase.

https://vuejs.org/v2/guide/components.html#camelCase-vs-kebab-case

In your case, something like this:

<test-item test-prop="My Test Prop Inside Wrapper"></test-item>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.