0

For some reason, the value for customer_data.customerReference is never available yet I can see using Chrome debugging tools that the data exists in the prop and is successfully passed from my app down to the component.

Vue.component("mycomponent", {
    template: '#my-component-template',
    props: ["customer_data"],
    data() {
        return {
              myData: 'This works fine!',
            form_data: {
                customerRef: this.customer_data.customerReference
            }
    }
}
});

new Vue({
    el: "#app",
    data() {
        return {
            customer: {
                customerReference: 007
            }
        };
    }
});

Here is my markup including the template:

<div id="app">
    <mycomponent customer_data="customer" />
</div>

<script type="x-template" id="my-component-template">
    <div>
        <p>{{form_data.customerRef}}</p>
        <p>{{myData}}</p>
    </div>
</script>

Please see the following JsFiddle with a simplified example: https://jsfiddle.net/ProNotion/a8c6nqsg/20/

What is that I am missing here or implementing incorrectly?

1
  • 1
    v-bind:customer_data="customer", without v-bind, you're just passing down the string 'customer' Commented Aug 26, 2019 at 15:56

2 Answers 2

2

You should bind it using v-bind: or just :

   <div id="app">
      <mycomponent :customer_data="customer" />
    </div>

https://v2.vuejs.org/v2/guide/components-props.html

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

1 Comment

In this case, you are correct, a typo in my example however in my app for some reason the issue persists. I will need to try and replicate the issue in my JsFiddle
0

You're passing in a string that says 'customer' and not the actual customer object. All you need to do is change customer_data="customer" to v-bind:customer_data="customer"

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.