我正在尝试导入一个函数,该函数返回一个it -html模板,然后呈现它。如果我在适当的地方定义了函数,模板就会成功地呈现,但是如果我尝试动态地导入模板,它就会呈现[object Object]。
import { render } from "lit-html";
import("/private.js").then(module => {
// function sayHello(name) {
// return html`<h1>Hello ${name}</h1>`;
// }
// they appear to be identical objects
// console.log("mod", module.default("beans")); // this renders properly
// console.log("new", sayHello("beans")); // this doesn't
render(module.default("beans"), document.querySelector("#app"));
});private.js:
import { html } from "lit-html";
export default function sayHello(name) {
return html`<h1>Hello ${name}</h1>`;
}发布于 2020-05-21 22:07:31
问题是,因为这两个文件是单独的构建,所以都包含lit html,这会导致错误。
https://stackoverflow.com/questions/61935367
复制相似问题