【问题标题】:Vuejs get arrays under array in dropdownVuejs在下拉列表中获取数组下的数组
【发布时间】:2020-07-19 09:28:52
【问题描述】:

我有这样的数据

问题

我无法访问我的data 下的tubes 数组

代码

script

data() {
    return {
        types: []
    }
},
methods: {
    handleChange (val) {
        axios.get(`/api/admin/getFromTubes/${val}`)
        .then(res => {
            this.types = res.data.data.tubes;
        })
        .catch(error => {
            console.log(error);
        })
    }
}

template

<el-form-item label="Old Core">
    <el-select style="width: 100%;" filterable clearable v-model="form.old_core_id" placeholder="Select Old Core">
        <el-option
        v-for="cable in types"
        :key="cable.id"
        :label="cable.name"
        :value="cable.id">
            <span style="float: left">
                {{ cable.name }}
            </span>
        </el-option>
    </el-select>
</el-form-item>

问题

如何在模板选择(下拉)中获取我的tubes 数组?

【问题讨论】:

    标签: javascript arrays vue.js vuejs2 vue-component


    【解决方案1】:

    不应该是:

    handleChange (val) {
        axios.get(`/api/admin/getFromTubes/${val}`)
        .then(res => {
            this.types = res.data[0].tubes;
        })
        .catch(error => {
            console.log(error);
        })
    }
    

    实际上

    this.types = res.data.data[0].tubes;
    

    【讨论】:

      猜你喜欢
      • 2015-10-04
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 2015-10-05
      • 2015-04-17
      • 1970-01-01
      • 1970-01-01
      • 2014-08-11
      相关资源
      最近更新 更多