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

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

vue 3 發(fā)出警告“無(wú)關(guān)的非發(fā)射事件監(jiān)聽器”

vue 3 發(fā)出警告“無(wú)關(guān)的非發(fā)射事件監(jiān)聽器”

繁星淼淼 2023-04-20 16:40:11
我正在嘗試使用組合 API 將數(shù)據(jù)從子項(xiàng)發(fā)送到父項(xiàng)我收到以下警告。[Vue 警告]:無(wú)關(guān)的非發(fā)射事件偵聽器 (updatedcount) 已傳遞給組件但無(wú)法自動(dòng)繼承,因?yàn)榻M件呈現(xiàn)片段或文本根節(jié)點(diǎn)。如果偵聽器僅用作組件自定義事件偵聽器,請(qǐng)使用“emits”選項(xiàng)聲明它。在 <HelloWorld onUpdatedcount=fn > at子組件.vue<template>  <h1>{{ store.count }}</h1>  <button @click="fired">click me</button></template><script>import useStore from "../store/store.js";export default {  name: "HelloWorld",  setup(_,{ emit }) {    const store = useStore();    const fired = () => {      store.count++;      emit("updatedcount", store.count);    };    return {      store,      fired    };  },};</script>父組件.vue<template>  <div>    {{ hello }}    <br />    <br />    <input type="text" v-model="hello.searchQuery" />    <br><br>    <button @click="hello.count--">click me too!</button>    <hello-world @updatedcount="mydata" />  </div></template><script>import HelloWorld from "./components/HelloWorld.vue";import useStore from "./store/store.js";export default {  components: {    HelloWorld,  },  setup() {    const hello = useStore();    function mydata(event) {      console.log(event);    }    return {      hello,      mydata    };  },};</script>
查看完整描述

4 回答

?
心有法竹

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

我認(rèn)為您需要emits在組件中定義:

export default {

? name: "HelloWorld",

? emits: ["updatedcount"], // <--- add this line

? setup(_,{ emit }) {

? ? ...

? },

};


查看完整回答
反對(duì) 回復(fù) 2023-04-20
?
滄海一幻覺(jué)

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

更新:


在 vue 3 腳本設(shè)置中你會(huì)做


const emits = defineEmits(["updatedcount"])


emits("updatedcount", store.count);


查看完整回答
反對(duì) 回復(fù) 2023-04-20
?
牛魔王的故事

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

當(dāng)在我自己的 vue 3 應(yīng)用程序中看到此錯(cuò)誤時(shí),我發(fā)現(xiàn)將組件的模板內(nèi)容包裝在一個(gè)空的 div 中可以解決我認(rèn)為與錯(cuò)誤消息的“無(wú)法自動(dòng)繼承”部分有關(guān)的問(wèn)題。


似乎 vue 的工作方式是 vue 將嘗試對(duì) @click 和 @input 等常見事件使用屬性繼承以傳遞給底層元素,但是當(dāng)組件的根部有多個(gè)同級(jí)元素時(shí),它不知道要傳遞哪個(gè)選擇。


請(qǐng)注意,這些事件可能會(huì)改變某些行為,因?yàn)樾碌陌b父 div 現(xiàn)在將直接綁定到它的事件。


<template>

  <div>

    <h1>{{ store.count }}</h1>

    <button @click="fired">click me</button>

  </div>

</template>


查看完整回答
反對(duì) 回復(fù) 2023-04-20
?
慕虎7371278

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

在 vue3 中你必須定義 emits,你的子組件看起來(lái)像這樣:


子組件.vue:


    <template>

      <h1>{{ store.count }}</h1>

      <button @click="fired">click me</button>

    </template>

    

    <script>

    import useStore from "../store/store.js";

    export default {

      name: "HelloWorld",

      emits :{

          updatedcount: null, <--- add this lines

        },

      data: () => ({

            store: useStore(),

      }),

      methods:

        fire () {

          store.count++;

          this.$emit("updatedcount", store.count);

        },

      

    };

    </script>


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

添加回答

舉報(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)