【发布时间】:2021-09-30 07:32:22
【问题描述】:
一切都运行得很好,直到突然就不行了。
我有一个带有点击事件的按钮。当我点击它时,它会调用方法 giveToParent() 发出一个字符串:
<template>
<div>
<button @click="giveToParent()">search</button>
</div>
</template>
<script>
export default {
...
methods: {
giveToParent() {
var sql = "select * from xxxxx where min_Price=20";
this.$emit("clicked", sql);
console.log(this.$emit("clicked", sql));
},
在父级 (app.vue) 中看起来像这样:
<template>
<Menu_Filter @clicked="test()"></Menu_Filter>
</template>
<script>
import Menu_Filter from "./components/Menu_Filter";
import { loadMap } from "./packs/my_js_file.js";
export default {
...
},
methods: {
test(value) {
logInConsole(value);
loadMap(value);
},
},
};
错误信息如下: 如您所见,它说对象不是函数,这是真的,因为 $emit 函数似乎是一个 vue 组件。我可以毫无问题地记录其他内容,所以它必须是 $emit 函数。
奇怪的是,这一切都奏效了,然后突然就不行了。我什至在我的笔记本电脑上有一个旧版本,当我尝试在那里执行它时,它也失败了。
我真的不知道为什么它不再起作用了。
【问题讨论】:
标签: javascript vue.js error-handling vue-component