如何解决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 举报,一经查实,本站将立刻删除。