1

I follow this vue doc to create a custom component with a custom attribute like this:

    Vue.component('y-form-checkbox', {
    props: ['chkLabel'],
    template: `<b-form-group label="label">
                <b-form-checkbox>
                  {{ chkLabel }}
                </b-form-checkbox>
            </b-form-group>`
    });

And then I use this component like following:

<y-form-checkbox chkLabel="Something special"></y-form-checkbox>

But the problem is that the chkLabel doesn't bind to the component's template as expected. I just got a checkbox without label. Why this happens? Thanks in advance!

1 Answer 1

2

You should use the cabab-case format instead of the camelCase one when dealing wthi props :

 <y-form-checkbox chk-label="Something special"></y-form-checkbox>

and keep it in camelCase format in component props declaration :

  Vue.component('y-form-checkbox', {
    props: ['chkLabel'],
    template: `<b-form-group label="label">
                <b-form-checkbox>
                  {{ chkLabel }}
                </b-form-checkbox>
            </b-form-group>`
    });

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.