相关疑难解决方法(0)

vue 3 发出警告“无关的非发射事件侦听器”

我正在尝试使用组合 API 将数据从子级发送到父级

我收到以下警告。

[Vue 警告]:无关的非发射事件侦听器 (updatedcount) 已传递给组件,但无法自动继承,因为组件呈现片段或文本根节点。如果侦听器仅用作组件自定义事件侦听器,请使用“发射”选项声明它。at <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>


Run Code Online (Sandbox Code Playgroud)

父组件.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> …
Run Code Online (Sandbox Code Playgroud)

javascript eventemitter vue.js vuejs3 vue-composition-api

33
推荐指数
3
解决办法
1万
查看次数