第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

錯(cuò)誤:“v-on 處理程序中的錯(cuò)誤:“TypeError:this.filter 未定義”

錯(cuò)誤:“v-on 處理程序中的錯(cuò)誤:“TypeError:this.filter 未定義”

我正在嘗試構(gòu)建一個(gè)創(chuàng)建過(guò)濾器按鈕的組件,然后通過(guò)事件總線發(fā)送過(guò)濾器對(duì)象中的類型屬性,以便在我的應(yīng)用程序的其他地方處理。但是,當(dāng)我在數(shù)據(jù)部分添加對(duì)象(過(guò)濾器)數(shù)組時(shí),單擊按鈕時(shí)出現(xiàn) this.filter is not defined 錯(cuò)誤。我想將過(guò)濾器數(shù)組保留在此組件中,因?yàn)槲疫€試圖將活動(dòng)類動(dòng)態(tài)更改為已單擊的任何按鈕。我錯(cuò)過(guò)了與道具有關(guān)的東西嗎?當(dāng)數(shù)據(jù)和 v-for 在另一個(gè)組件上時(shí),為什么我無(wú)法顯示按鈕?為了解決這個(gè)問(wèn)題,我一直在問(wèn)自己這些問(wèn)題。<template>  <div>    <button      v-for="(filter, index) in filters"      :key="index"      :class="{ active: index === activeItem }"      @click="emitFilter(), selectItem(index)"      :filter="filter"    >      {{ filter.name }}    </button>  </div></template><script>import EventBus from '@/components/EventBus'export default {  props: {    filter: { type: String }  },  data() {    return {      activeItem: 0,      filterResult: '',      filters: [        { name: 'All', type: 'all' },        { name: 'Holidays', type: 'holiday' },        { name: 'Seasons', type: 'season' },        { name: 'Events', type: 'custom' }      ]    }  },  methods: {    emitFilter() {      this.filterResult = this.filter      EventBus.$emit('filter-catagories', this.filterResult)    },    selectItem(index) {      this.activeItem = index    }  }}</script>我的按鈕組件用于過(guò)濾器組件<template>  <div>    <span>filters</span>      <FilterBtn />    </div>  </div></template><script>import FilterBtn from '@/components/FilterBtn'export default {  components: {    FilterBtn      }  // data() {  //   return {  //     filters: [  //       { name: 'All', type: 'all' },  //       { name: 'Holidays', type: 'holiday' },  //       { name: 'Seasons', type: 'season' },  //       { name: 'Events', type: 'custom' }  //     ]  //   }  // }}</script>如您所見,注釋部分是我最初擁有過(guò)濾器的地方,但我不得不將它們移至按鈕組件以添加活動(dòng)類。
查看完整描述

4 回答

?
拉風(fēng)的咖菲貓

TA貢獻(xiàn)1995條經(jīng)驗(yàn) 獲得超2個(gè)贊

我假設(shè)您實(shí)際上是在嘗試訪問(wèn)from within的filter迭代器。為此,您需要在綁定中傳遞itself :v-for="(filter, index) in filters"emitFilter()filter@click


<button v-for="(filter, index) in filters"

        @click="emitFilter(filter)">

然后,您的處理程序可以直接使用參數(shù):


export default {

  methods: {

    emitFilter(filter) {

      this.filterResult = filter

      //...

    }

  }

}


查看完整回答
反對(duì) 回復(fù) 2022-12-22
?
白板的微信

TA貢獻(xiàn)1883條經(jīng)驗(yàn) 獲得超3個(gè)贊

您正在將一個(gè)名為filtertyped的道具傳遞string給您的組件。當(dāng)您輸出時(shí),{{ filter.name }}您實(shí)際上是在引用此屬性,而不是filter您在 v-for 循環(huán)中創(chuàng)建的變量。

除非您將名為“filter”的屬性傳遞給您的組件,否則該屬性將是未定義的。因此輸出filter.name將導(dǎo)致此錯(cuò)誤消息。



查看完整回答
反對(duì) 回復(fù) 2022-12-22
?
陪伴而非守候

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個(gè)贊

您正在將一個(gè)名為filtertyped的道具傳遞string給您的組件。當(dāng)您輸出時(shí),{{ filter.name }}您實(shí)際上是在引用此屬性,而不是filter您在 v-for 循環(huán)中創(chuàng)建的變量。

除非您將名為“filter”的屬性傳遞給您的組件,否則該屬性將是未定義的。因此輸出filter.name將導(dǎo)致此錯(cuò)誤消息。


查看完整回答
反對(duì) 回復(fù) 2022-12-22
?
回首憶惘然

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超11個(gè)贊

是的,你沒(méi)有將 prop 傳遞給你的組件,這就是為什么它是未定義的。

<FilterBtn filter="test" />

在這里,我傳遞了一個(gè)名為 propfilter的值test。

當(dāng)然你可以傳遞動(dòng)態(tài)道具。綁定就行了

<FilterBtn :filter="yourData" />

我需要問(wèn):你傳遞的是對(duì)象還是字符串?

因?yàn)槟鷮?prop 定義為字符串,但實(shí)際上將其用作對(duì)象

  {{ filter.name }}

也許您還應(yīng)該將類型設(shè)置為 Object。

  props: { 
     filter: { type: Object }
  },


查看完整回答
反對(duì) 回復(fù) 2022-12-22
  • 4 回答
  • 0 關(guān)注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)