ホームページ  >  に質問  >  本文

フィルター関数で使用されるプロパティを表示 - axios、vue3

axios を使用してデータを取得するときに filteredProducts にプロパティを表示する方法。以下に示すようにpropsを渡しました。

リーリー

「Nike」をブランド名に置き換えて継承したいと考えています。どうもありがとうございます###

P粉439804514P粉439804514407日前535

全員に返信(2)返信します

  • P粉872101673

    P粉8721016732023-09-09 09:13:18

    「Nike」という名前の製品を選択し、filteredProducts に渡します。その後、計算されたプロパティを使用して名前を変更し、それをテンプレートで使用できます。

    リーリー

    返事
    0
  • P粉529245050

    P粉5292450502023-09-09 09:09:06

    export default {
                  data() {
                    return {
                      products: [],
                    };
                  },
                  mounted() {
                       this.getSneakers();
                  },
                  methods: {
                     getSneakers() {
                     axios
                      .get('/src/stores/sneakers.json')
                       .then(response => { 
                      this.products = response.data ?? [];
                          })
                      }
                   },
                  computed: {
                        resultCount () {
                            return this.filteredProducts?.length ?? 0
                        },
                        brandName() {
                            return this.brand?.name ?? "";
                        },
                        filteredProducts () {
                            return this.products?.filter(
            product => product.name?.toLowerCase()?.includes(this.brandName.toLowerCase())
                       )
                        },
                    },
                  props: {
                    brand: {
                      type: Object,
                    },
                  },
              }

    返事
    0
  • キャンセル返事