StencilJS 中的 xml2Js

问题描述

我正在尝试将 xml 响应转换为 json,在 stenciljs 组件中使用 xml2js,但在控制台中出现错误。请帮忙。

代码不多,只有一个基本的 stenciljs 组件。

import { Component,Prop,h } from '@stencil/core';
import xml2js from 'xml2js';

@Component({
  tag: 'my-component'
})
export class MyComponent {
  @Prop() text: string = 'component';

  componentDidLoad() {
    var xml = "<foo attr=\"value\">bar</foo>";
    xml2js.parseString(xml,function (err,result) {
      console.dir(result);
      console.log('Done');
    });
  }


  render() {
    return (
      <div>My first {this.text}</div>
    );
  }
}

这里是错误

index-143e0751.js:2706 TypeError: Cannot read property 'prototype' of undefined
    at extend (my-component.entry.js:561)
    at my-component.entry.js:575
    at my-component.entry.js:853
    at my-component.entry.js:855
    at createCommonjsModule (my-component.entry.js:16)
    at my-component.entry.js:557 undefined
consoleError @ index-143e0751.js:2706
Promise.then (async)
loadModule @ index-143e0751.js:2731
initializeComponent @ index-143e0751.js:1941
connectedCallback @ index-143e0751.js:2100
(anonymous) @ index-143e0751.js:2438
jmp @ index-143e0751.js:25
connectedCallback @ index-143e0751.js:2438
(anonymous) @ index-143e0751.js:2473
bootstrapLazy @ index-143e0751.js:2473
(anonymous) @ plansummary.esm.js:121
Promise.then (async)
(anonymous) @ plansummary.esm.js:119
index-143e0751.js:1949 Uncaught (in promise) Error: Constructor for "my-component#undefined" was not found
    at initializeComponent (index-143e0751.js:1949)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)