6

I'm trying to pass multiple variables in the following code:

<div v-bind:onloadstart='functionOFF = true; editOFF = true'></div>

but I get the following error:

[Vue warn]: Failed to generate render function: SyntaxError: Unexpected token ; in

I tried replacing the ; with a , but the I get:

[Vue warn]: Failed to generate render function: SyntaxError: Invalid shorthand property initializer in

Any ideas on how to achieve this?

6
  • move those into metrod? Commented Jul 12, 2018 at 9:52
  • @dfsq - yeah I though about that, just wanted to see if there's a way to doing it directly Commented Jul 12, 2018 at 9:54
  • try to do it with & or && operator maybe Commented Jul 12, 2018 at 9:55
  • @JulienMetral - Yeah I tried with both and I get a compiling error Commented Jul 12, 2018 at 9:58
  • To listen to a method, you should use v-on:onloadstart='functionOFF = true; editOFF = true' Commented Jul 12, 2018 at 10:04

6 Answers 6

5

also, you can use from below way:

<input v-bind:value="[item.id, item.name]">
Sign up to request clarification or add additional context in comments.

1 Comment

you are a legend! Ty for posting this
3

spreading them in to object and using them in bind if object else add them like shown..

<MyComponent v-bind="{...$attrs, featAProps, featBProps}" />

Comments

0

You can use anonymous function if you don't want to declare a method:

<div v-bind:onloadstart='()=>{functionOFF = true; editOFF = true;}'></div>

Comments

0

According to document, v-bind should be an value or an object.

v-bind

Expects: any (with argument) | Object (without argument)

Argument: attrOrProp (optional)

You should use v-on to listen to event (in this case onloadstart). v-on can use with Inline Statement

v-on

Expects: Function | Inline Statement | Object

Argument: event

<div v-on:onloadstart='functionOFF = true; editOFF = true'></div>

2 Comments

I've tried it and it does render the page but now the value of the variables aren't changed :s
I think onloadstart might not be supported by major browser (developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/…). You should put functionOFF = true; editOFF = true in created hook of Vue component.
0

In Vue 3, I wasn't having much luck with the array syntax

<MyComponent v-bind="[$attr, propA]">

but I found this comment in Vue's github repo.

This led me to try

<MyComponent v-bind="($attrs, props)" :anotherProp="anotherProp">

which ended up working for me.

Comments

0

FOR VUE.js ^3.3.4 and Vuetify ^3.5.0

Just tried object destruction way on the props and attributes I want to bind my button component, and it worked.

For presentation, I was trying to construct a menu button with activator props and dynamic attributes definitions for colors, custom classes etc..

 <v-menu>
        <template v-slot:activator=" { props, isActive }">
          <v-btn
            v-bind="{...props, ...filterBtnOptions}"
            variant="elevated"
          >
            {{ `${filterActive.name} (${filterActive.number})` }}
            <v-icon right :style="{ transform: isActive ? 'rotate(-180deg)' : 'rotate(0)' }">mdi-chevron-down</v-icon>
          </v-btn>
        </template>
        //..code
 </v-menu>

Here props is the activator props of the menu component and filterBtnOptions is a custom attribute object.

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.