【问题标题】:Vue - how to loop through values in arrayVue - 如何遍历数组中的值
【发布时间】:2020-02-11 11:37:04
【问题描述】:

有没有办法使用v-select 来显示数组的值?我需要列出这个数组的str 值:

myArr: [
            { key: 'one', str: '1st' },
            { key: 'two', str: '2nd' },
            { key: 'three', str: '3rd' },
            { key: 'four', str: '4th' }
]

v-select,但不知道该怎么做。到目前为止,我已经完成了这项工作:

<v-select v-model="vCase.eligibility" :items="eligPeriods[0].str"></v-select>

它在v-select 中显示“1st”。但我需要显示所有值。

我尝试使用模板:

<template v-slot:myArr="{item}">
        <v-select v-model="myVar.selectedVal" :items="item[str]"></v-select>
</template>

但它甚至不会在页面上呈现。

有什么帮助或建议吗?

【问题讨论】:

    标签: arrays vue.js v-select


    【解决方案1】:

    因为你有一个关联数组作为项目,你需要做这样的事情

    <v-select :options="myArr" :reduce="item => item.key" label="item.str" />
    

    您可以阅读更多关于它的信息here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-08
      • 2019-06-18
      • 2019-09-04
      • 2020-07-01
      • 2011-11-27
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      相关资源
      最近更新 更多