Reputation: 413
I am attempting to pass a array of strings to a prop...
<vue-component attributes="[Attribute0, Attribute1, Attribute2]"></vue-component>
Here is my component
<template>
<div id="app">
<ul class="content" v-bind:style="{ display: computedDisplay }" >
<li v-for="(attribute, index) in Attributes" v-bind:key="attribute">{{index}} + " " + {{attribute}}</li>
</ul>
</div>
</template>
<script>
export default {
name: 'app',
props: {
elementName: {
type: String,
required: true
},
Attributes: {
type: Array,
required: false
}
},
</script>
What i was expecting was a for three elements "Attribute0"."Attribute1","Attribute3" would be created in my v-for loop, however its treating what i passed it as an array of characters....
Here is the output
0 + " " + [
1 + " " + A
2 + " " + t
3 + " " + t
4 + " " + r
5 + " " + i
6 + " " + b
7 + " " + u
8 + " " + t
9 + " " + e
10 + " " + 0
11 + " " + ,
12 + " " +
13 + " " + A
14 + " " + t\
...
What is the correct syntax for passing an array of strings to a prop?
Upvotes: 7
Views: 14126
Reputation: 3116
You are actually passing a string here if you read carefully:
<vue-component attributes="[Attribute0, Attribute1, Attribute2]"></vue-component>
You should be able to pass an array of strings like this:
<vue-component :attributes="['Attribute0', 'Attribute1', 'Attribute2']"></vue-component>
Upvotes: 16
Reputation: 50
You should use :
before the prop, and use quotes:
<vue-component :attributes="['Attribute0', 'Attribute1', 'Attribute2']"></vue-component>
Upvotes: 2