wiryadev
wiryadev

Reputation: 1491

Unable to pass more than one props in Vue3

I want to pass 2 props to my components. Both are String, but only the title props can be passed in. I checked the posterUrl by passing the url to title props and it works. But the title can not be received when i send it as poster. So i'm sure its not the data that has problem.

Then i tried to use default value, and the image shows up but they are all using the default value. I've tried using shorthand, v-bind, and standard use, nothing works.

The components looks like this

    app.component('item-movie', {
        props: {
            title: String,
            posterUrl: {
                type: String,
                default: "https://image.tmdb.org/t/p/original/5NYdSAnDVIXePrSG2dznHdiibMk.jpg",
            },
        },
        template:
            /*html*/
            `
        <div class="col-md" style="margin-bottom: 2rem; margin-top: 2rem;">
            <img class="img-fluid" style="min-width: 300px;" v-bind:src="posterUrl">
            <p style="margin-top: 1rem; margin-bottom: -0.3rem; color: white;">{{ title }}</p>
        </div>
        `,
    })

I use it like this

        <item-movie v-for="movie in movies" :key="movie.id"
          :title="movie.title" :posterUrl="imageUrl+movie.poster_path">
        </item-movie>

Upvotes: 2

Views: 1336

Answers (1)

Michal Lev&#253;
Michal Lev&#253;

Reputation: 37793

When using in-DOM templates (template as part of the HTML), pascal cased attribute/prop names (such as "posterUrl") needs to be converted to kebab-case - "poster-url"

Docs

HTML attribute names are case-insensitive, so browsers will interpret any uppercase characters as lowercase. That means when you're using in-DOM templates, camelCased prop names need to use their kebab-cased (hyphen-delimited) equivalents

Upvotes: 6

Related Questions