Home > Software engineering >  Unable to pass more than one props in Vue3
Unable to pass more than one props in Vue3

Time:12-10

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  style="margin-bottom: 2rem; margin-top: 2rem;">
        <img  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>

Version Used: Vue 3

CodePudding user response:

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

  • Related