1

I'm trying to pass an object property into a click event. I know you cannot pass curly brackets into html attributes since I have the title property output correctly. But how to do the same when trying to render a click event?

<p class="control" v-for="range in ranges">
    <a class="button is-outlined is-primary has-text-black" :title="range.title" @click="getNumber({{ range.id }})">{{ range.title }}</a>
</p>

invalid expression: expected property name, got '{' in

    getNumber({{ range.id }})

  Raw expression: @click="getNumber({{ range.id }})"

3 Answers 3

1
getNumber(`${ range.id }`)

Should do the trick

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

1 Comment

Your solution also worked as I'm new to Vue so I attempt each different answer.
0

add key in v-for... And @click="getNumber({{range.id}})" to @click="getNumber(range.id)"

<p class="control" v-for="(range, key) in ranges" :key="key">
        <a class="button is-outlined is-primary has-text-black" :title="range.title" @click="getNumber( range.id )">{{ range.title }}</a>
    </p>

    methods: {
    getValueNumber(value){
    console.log(value)
    }
    }

1 Comment

While your change to getNumber() was accurate, adding the key index gave me a warning: Property or method "key" is not defined on the instance but referenced during render.
0

Please change @click="getNumber({{ range.id }})" to @click="getNumber(range.id )". Vue had compile it when variable in function.

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.