将字符串数组传递给 prop vue

mat*_*att 3 javascript vue.js

我试图将一个字符串数组传递给一个道具......

<vue-component  attributes="[Attribute0, Attribute1, Attribute2]"></vue-component>
Run Code Online (Sandbox Code Playgroud)

这是我的组件

<vue-component  attributes="[Attribute0, Attribute1, Attribute2]"></vue-component>
Run Code Online (Sandbox Code Playgroud)

我期待的是三个元素“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\
...
Run Code Online (Sandbox Code Playgroud)

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

ajo*_*obi 9

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

<vue-component attributes="[Attribute0, Attribute1, Attribute2]"></vue-component>
Run Code Online (Sandbox Code Playgroud)

您应该能够像这样传递一个字符串数组:

<vue-component :attributes="['Attribute0', 'Attribute1', 'Attribute2']"></vue-component>
Run Code Online (Sandbox Code Playgroud)

  • @matt `:` 最终只是一个 `v-bind` :https://v1.vuejs.org/guide/syntax.html#v-bind-Shorthand (3认同)