Vue "emit" 替代方案
Vue "emit" alternative
Vue 在我使用“emit”时抱怨 我正在寻找功能相同的替代方案
这将是一个待办事项列表
代码:
<button @click="$emit('delete-todo-event', todo.id)">Button</button>
浏览器控制台中的警告:
runtime-core.esm-bundler.js?5c40:38 [Vue warn]: Extraneous non-emits event listeners deleteTodoEvent) were passed to component but could not be automatically inherited because component renders fragment or text root nodes. If the listener is intended to be a component custom event listener only, declare it using the "emits" option. at <ToDos todoEntries= (9) [Proxy, Proxy, Proxy, Proxy, Proxy, Proxy, Proxy, Proxy, Proxy] onDeleteTodoEvent=fn<bound deleteToDoItem> > at <App>
您似乎在使用 Vue 3。警告告诉您在组件中使用事件之前没有声明事件。这是一个例子:
export default {
name: "YourComponent",
emits: ["deleteTodoEvent"], // <--- this is what the warning in hinting to
setup(_,{ emit }) {
...
},
};
Vue 在我使用“emit”时抱怨 我正在寻找功能相同的替代方案
这将是一个待办事项列表
代码:
<button @click="$emit('delete-todo-event', todo.id)">Button</button>
浏览器控制台中的警告:
runtime-core.esm-bundler.js?5c40:38 [Vue warn]: Extraneous non-emits event listeners deleteTodoEvent) were passed to component but could not be automatically inherited because component renders fragment or text root nodes. If the listener is intended to be a component custom event listener only, declare it using the "emits" option. at <ToDos todoEntries= (9) [Proxy, Proxy, Proxy, Proxy, Proxy, Proxy, Proxy, Proxy, Proxy] onDeleteTodoEvent=fn<bound deleteToDoItem> > at <App>
您似乎在使用 Vue 3。警告告诉您在组件中使用事件之前没有声明事件。这是一个例子:
export default {
name: "YourComponent",
emits: ["deleteTodoEvent"], // <--- this is what the warning in hinting to
setup(_,{ emit }) {
...
},
};