【问题标题】:vue-class-component: Super expression must either be null or a function, not undefinedvue-class-component:超表达式必须是null或者函数,不能是undefined
【发布时间】:2018-09-25 23:58:30
【问题描述】:

好的,这是一个奇怪的用例,但无论如何。

我有一个包含菜单组件的控件组件,它还包含一个控件组件但没有菜单(奇怪的东西,但这是设计)。

我做什么。

控件组件:

import {Component, Prop, Vue} from 'vue-property-decorator'
import Burger from "./Burger";
import ShadowLogo from "./ShadowLogo";
import MegaMenu from "./MegaMenu";

@Component
export default class Controls extends Vue {
  @Prop({default: false})
  showMenu: boolean;

  renderLogo(h) {
    return <div class="logo"><ShadowLogo/></div>
  }

  renderBurger(h) {
    return <Burger opened={this.showMenu} label="меню" on-want-change={e => this.$emit('show-menu', !this.showMenu)}></Burger>
  }

  renderFooter(h) {
    return <div class="copyrights"></div>
  }

  renderMenu(h) {
    return <div class="menu-layer">
      {this.showMenu ? <transition name="fade" appear={true}><MegaMenu/></transition> : null}
    </div>
  }

  render(h) {
    return <div class={["control-overlay", this.showMenu ? 'menu-opened' : null]}>
      {this.renderMenu(h)}
      {this.renderLogo(h)}
      {this.renderBurger(h)}
      {this.renderFooter(h)}
    </div>
  }
}

要插入到菜单中的菜单内部控件组件 — 相同,但没有菜单组件(显然是为了防止递归)

import Controls from "./Controls";
import {Component} from 'vue-property-decorator'

@Component
export default class MenuInnerControls extends Controls {
  renderMenu(h) {
    return null;
  }
}

但是在这个设置中我得到一个错误:

51:13 Uncaught TypeError: Super expression must either be null or a function, not undefined
    at _inherits (51:13)
    at eval (51:19)
    at eval (MenuInnerControls.js?9737:8)
    at Object.<anonymous> (app.js:394)
    at __webpack_require__ (app.js:20)
    at eval (22:4)
    at Object.<anonymous> (app.js:219)
    at __webpack_require__ (app.js:20)
    at eval (18:8)
    at Object.<anonymous> (app.js:192)

(MenuInnerControls.js?9737:8 — 是继承类中的 renderMenu 方法)

【问题讨论】:

  • 我对 Vue 的装饰器不熟悉,难道是你必须实现构造函数并调用 super 吗?
  • @MaartenBicknese nope

标签: javascript vue.js vue-class-components


【解决方案1】:

好的,发现问题出在导入的循环依赖中。 Controls 渲染 MegaMenu 渲染 MenuInnerControls 扩展 Controls。 即使MenuInnerControls 没有引用MegaMenu,这也会导致导入中的循环依赖。应该不是其他语言的问题,但是js...哦

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-01
    • 2017-04-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-07
    • 2016-09-23
    • 2023-01-29
    相关资源
    最近更新 更多