我正在尝试使用组合 API 将数据从子项发送到父项
我收到以下警告。
[Vue 警告]:无关的非发射事件侦听器 (updatedcount) 已传递给组件但无法自动继承,因为组件呈现片段或文本根节点。如果侦听器仅用作组件自定义事件侦听器,请使用“emits”选项声明它。在 <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>
心有法竹
沧海一幻觉
牛魔王的故事
慕虎7371278
相关分类