gpt4 book ai didi

javascript - 将字符串数组传递给 prop vue

转载 作者:行者123 更新时间:2023-12-02 21:47:40 25 4
gpt4 key购买 nike

我正在尝试将字符串数组传递给 Prop ...

<vue-component  attributes="[Attribute0, Attribute1, Attribute2]"></vue-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>

我期望的是三个元素“Attribute0”。“Attribute1”,“Attribute3”将在我的 v-for 循环中创建,但是它将我传递的内容视为字符数组....

这是输出

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\
...

将字符串数组传递给 prop 的正确语法是什么?

最佳答案

如果您仔细阅读,您实际上是在此处传递一个字符串:

<vue-component attributes="[Attribute0, Attribute1, Attribute2]"></vue-component>

您应该能够传递如下所示的字符串数组:

<vue-component :attributes="['Attribute0', 'Attribute1', 'Attribute2']"></vue-component>

关于javascript - 将字符串数组传递给 prop vue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60216899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com