大家好,我正在开发一个 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)