簡體   English   中英

如何將 api 數據值放入類星體框架的 select 選項中?

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


我正在嘗試將我的 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']"
/>

這是獲取 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)
    })
  },
}

我試圖將我的 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']"
/>

這是獲取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)
    })
  },
}

我遲到了,但你需要延遲加載 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);
      },

然后在你的 q-select 中有@filter="filterFn"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM