小编Pos*_*stR的帖子

ReferenceError:在初始化之前无法访问词法声明“Tag”

大家好,我正在开发一个 Vanilla JS SPA 项目,我想实现 React 的一些原则,但只是用普通的 JavaScript。但是导入类有一个问题,我不确定发生了什么。我浏览了类似主题的一些答案,但到目前为止没有任何帮助。

于是就有了一个带有Class Tag的index.js文件。

import { banner } from './components/banner.js';

export class Tag {
constructor(parent, child, attribute, text) {
    this.parent = parent;
    this.child = child;
    this.attribute = attribute;
    this.text = text;
    }
}

Tag.prototype.createTagElement = function() {
  let parent = this.parent;
  let child = this.child;
  let attribute = this.attribute;
  let text = this.text;

  child = document.createElement(child);
  parent.appendChild(child);
  child.innerHTML = text;

  for (let key in attribute) {
    if (attribute.hasOwnProperty(key)) {
        let value = attribute[key]; 

        child.setAttribute(key, …
Run Code Online (Sandbox Code Playgroud)

javascript import scope export class

4
推荐指数
1
解决办法
8415
查看次数

标签 统计

class ×1

export ×1

import ×1

javascript ×1

scope ×1