javascript - (Laravel/Vue/Tiptap)TypeError:没有'new'就不能调用类构造函数”
问题描述
我正在 Laravel/Vue 中开发一个应用程序,对于一个特定的组件,我需要一个自定义版本的扩展“Mention”到文本编辑器包“Tiptap”。我在一个单独的 .js 文件中创建了一个新类,它扩展了 Mention 以包含我需要的功能,如下所示:
import { Mention } from 'tiptap-extensions';
export default class SpecialMention extends Mention {
constructor(props) {
super(props);
}
get name() {
//
}
get schema() {
//
}
}
在代码中构造一个对象,如下所示:
import SpecialMention from './SpecialMention';
new SpecialMention({
matcher: {
char: '@',
allowSpaces: true,
startOfLine: false,
},
items: vm.prepareItems(vm.properties, "property"),
...extensionFunctions
}),
虽然代码编译没有问题,但我遇到了以下运行时错误:
"TypeError: Class constructor Mention cannot be invoked without 'new'"
我以前看到过这个问题,他们倾向于指出 Babel 是原因。不幸的是,我对 Babel 完全不熟悉。我尝试将其回滚,但没有成功,并根据类似问题的解决方案将target.esmodules 和 targets.node 配置为 true (在 package.json 中):
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": true,
"esmodules": true
}
}
]
],
"plugins": [
"@babel/plugin-proposal-optional-chaining"
]
}
这是转译的代码 - 失败在最后一行:
function SpecialMention() {
_classCallCheck(this, SpecialMention);
return _possibleConstructorReturn(this, _getPrototypeOf(SpecialMention).apply(this, arguments));
}
但是,我仍然得到相同的运行时错误。有谁可能是什么解决方案?非常感谢。
解决方案
推荐阅读
- c# - 从企业代理后面使用 .Net Core 3.00 对 Azure AD 进行身份验证
- javascript - 未捕获的 ReferenceError:getSelectedOption 未在 HTMLButtonElement.document.getElementById.onclick 中定义
- javascript - 如何在不重新加载页面的情况下将数据从 HTML 页面传递到 PHP 脚本?
- java - Java:如何可视化/绘制两个参数与矩阵的关系
- series - AmCharts 4:无法自定义(颜色、笔触宽度)我的系列
- c# - 在 C# 中将唯一值插入 SQL Server 的问题
- javascript - React + Typescript 中渲染组件的问题
- javascript - 如何将我的 React 类更改为一个函数,以便我可以包含 Material UI 类?
- r - 监督分类:绘制不同样本大小和 k 值的 K-NN 精度
- angular - 将许多可观察对象组合成一个对象的简单方法