简体   繁体   English

如何将 api 数据值放入类星体框架的 select 选项中?

[英]How to put api data value into select options for quasar framework?


I am trying to put my api value into q-select but it is showing [object Object] for all the values我正在尝试将我的 api 值放入 q-select 但它显示所有值的[object Object]

<q-select
   v-model="product_brand"
   :options="brands"
   label="Product Brand *"
   lazy-rules
   :rules="[ val => val && val.length > 0 || 'Please select product brand']"
/>

Here is the script code for taking the api values这是获取 api 值的脚本代码

export default () {
  data () {
    return {
      brands: []
    }
  },
  created () {
   this.$axios.get(['http://127.0.0.1:8000/api/lailen-inventory/categories'])
    .then(res => {
      this.brands = res.data.categories
    })
    .catch(errors => {
      console.log(errors)
    })
  },
}

I am trying to put my api value into q-select but it is showing [object Object] for all the values我试图将我的 api 值放入 q-select 但它显示所有值的[object Object]

<q-select
   v-model="product_brand"
   :options="brands"
   label="Product Brand *"
   lazy-rules
   :rules="[ val => val && val.length > 0 || 'Please select product brand']"
/>

Here is the script code for taking the api values这是获取api值的脚本代码

export default () {
  data () {
    return {
      brands: []
    }
  },
  created () {
   this.$axios.get(['http://127.0.0.1:8000/api/lailen-inventory/categories'])
    .then(res => {
      this.brands = res.data.categories
    })
    .catch(errors => {
      console.log(errors)
    })
  },
}

im late but you need a lazy loading function我迟到了,但你需要延迟加载 function

      filterFn(val, update, abort) {
        //This function is used to lazy load the selects
        if (brands.value !== null) {
          // already loaded
          update();
          return;
        }
        setTimeout(() => {
          update(() => {
            brands.value = apiData;
          });
        }, 500);
      },

Then have @filter="filterFn" in your q-select然后在你的 q-select 中有@filter="filterFn"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM