Is there some way to make this work?
Vue.component('my-select', {
template: '<select options="options"></select>',
props: ['options']
})
Then on my page use:
<my-select options="[{text: 'Cats', value: 'cats'}]"></my-select>
More generally, is there some way to pass object/arrays to a custom component directly from the view?
try options="{{ [{text: 'Cats', value: 'cats'}] }}"
Perfect, thank you.
I ran into the same problem and the {{ }}
trick doesn't solve when using version 1.0.0. I managed to get it working with :options="[{text: 'Cats'}]"
.
Is this the right way to do it?
The same as @mattbit when using vue1.0.8
@mattbit @animabear curly braces are not supported for props since 1.0.0.
Thus :options="[{text: 'Cats'}]"
is the idiomatic way to do this.
@simplesmiler I see, thanks
change log: https://github.com/vuejs/vue/releases
You can also use single quotes for attribute, :items='[{text: "Cats"}]' if you generate json on backend, it uses double quotes by default.
In case anyone finds this issue from google searching for the same thing in Vue 2.0 and figures out that interpolation in props has been removed like I did, here is the proper way to do this is to simply do <custom-element v-bind:whatever="['test','test2']"></custom-element>
or <custom-element :whatever="['test','test2']"></custom-element>
.
@HelgeSverre Thanks! <3
If you try to bind an array as variable, you might need to do
<custom-element v-bind:whatever="[...array]"></custom-element>
or
<custom-element :whatever="[...array]"></custom-element>
which uses ES2015's spread syntax.
Thank you @nd9600. This was just what I needed to get my errors to go away. The funny thing was, it was still handing the array into the vars without data problems, just the warning.
I had the same problem... removed our friends {{ }} and baang! It worked.
@nd9600 thnak you for your solution. Worked for me!!
Most helpful comment
In case anyone finds this issue from google searching for the same thing in Vue 2.0 and figures out that interpolation in props has been removed like I did, here is the proper way to do this is to simply do
<custom-element v-bind:whatever="['test','test2']"></custom-element>
or<custom-element :whatever="['test','test2']"></custom-element>
.