0

I've spent two days, trying to solve this issue by myself but couldn't get it to work. Basically I declared all my props in the parent component but for some reason they don't show up at all.

Component

let addFilter = {
    props: ['newFilterName'],
    template:  `<div class="row">
                    <div class="field-options">{{ newFilterName }}</div>
                </div>`,
};

Instance

let filterManager = new Vue({
    el: '#filter-manager',
    components: {
        'add-filter': addFilter
    },
    data: {
        newFilterName: 'Test1234'
    }
});

HTML

<div id="filter-manager" v-show="visible">
    <div class="body">
        <add-filter></add-filter>
     </div>
</div>

1 Answer 1

2

you need to pass the data from the parent to the component

<div id="filter-manager" v-show="visible">
    <div class="body">
        <add-filter :new-filter-name="newFilterName" ></add-filter>
     </div>
</div>

To be clear :new-filter-name is the property of the child component and the right side "newFilterName" is the data property you defined in the parent. Just naming them the same doesn't do anything. You need the assignment when you instantiate the component.

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

2 Comments

Thanks for pointing that out. It does work now. Just one more humble ask maybe you could change your answer to <add-filter :new-filter-name="newFilterName" ></add-filter> so I can accepted.
Yes Justin, you are right :new-filter-name and :newFilterName both work.

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.