会发生什么?
Vuejs不会将v-on:click / @click视为事件处理程序,而是将其视为添加元素一样。并触发以下错误
vue.common.js:593 [Vue warn]: Unknown custom element: <click> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
found in
---> <OrderTable> at resources\assets\js\components\OrderTable\OrderTable.vue
<Page> at resources\assets\js\components\Pages\Page.vue
<Root>
warn @ vue.common.js:593
createElm @ vue.common.js:5570
addVnodes @ vue.common.js:5737
updateChildren @ vue.common.js:5864
patchVnode @ vue.common.js:5938
updateChildren @ vue.common.js:5824
patchVnode @ vue.common.js:5938
updateChildren @ vue.common.js:5824
patchVnode @ vue.common.js:5938
patch @ vue.common.js:6098
Vue._update @ vue.common.js:2672
updateComponent @ vue.common.js:2790
get @ vue.common.js:3144
run @ vue.common.js:3221
flushSchedulerQueue @ vue.common.js:2983
(anonymous) @ vue.common.js:1839
flushCallbacks @ vue.common.js:1760
我已经简化了发生错误的组件。但是触发错误的span
并没有什么特别的。它是根div
元素的子元素。此外,addRow
方法也无关紧要,因为无论将哪个函数绑定到click事件,都会发生错误。
<template>
<div>
<span v-on:click="addRow">Add new row</span>
</div>
</template>
<script>
export default {
name: "OrderTable",
methods: {
newRow: function () {
console.log('Adding new row')
},
}
这是来自app.js的有关元素的摘录:
_c("span", { on: { click: _vm.newRow } }, [_vm._v("Add new row")])