-
Notifications
You must be signed in to change notification settings - Fork 2.5k
浏览器报:Uncaught (in promise) ReferenceError: initWidget is not defined at autoload.js:36:3 #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
可以提供你的网站地址吗?看图片比较难定位问题的具体原因 |
同样报错,也是本地运行的,感谢大佬帮忙看看文件结构:
// live2d_path 参数建议使用绝对路径
const live2d_path = "./dist/";
//const live2d_path = "/live2d-widget/";
// 封装异步加载资源的方法
function loadExternalResource(url, type) {
return new Promise((resolve, reject) => {
let tag;
if (type === "css") {
tag = document.createElement("link");
tag.rel = "stylesheet";
tag.href = url;
}
else if (type === "js") {
tag = document.createElement("script");
tag.src = url;
}
if (tag) {
tag.onload = () => resolve(url);
tag.onerror = () => reject(url);
document.head.appendChild(tag);
}
});
}
// 加载 waifu.css live2d.min.js waifu-tips.js
if (screen.width >= 768) {
Promise.all([
loadExternalResource(live2d_path + "waifu.css", "css"),
loadExternalResource(live2d_path + "live2d.min.js", "js"),
loadExternalResource(live2d_path + "waifu-tips.js", "js")
]).then(() => {
// 配置选项的具体用法见 README.md
initWidget({
waifuPath: live2d_path + "waifu-tips.json",
//apiPath: "https://live2d.fghrsh.net/api/",
//cdnPath: "https://fastly.jsdelivr.net/gh/fghrsh/live2d_api/",
tools: ["hitokoto", "asteroids", "switch-model", "switch-texture", "photo", "info", "quit"]
});
});
} 前端文件: <!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Live2D 看板娘示例</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css">
<body>
<h1>Live2D 看板娘演示</h1>
<p>这是一个 Live2D 看板娘的演示页面。</p>
<!-- 加载本地 autoload.js -->
<script src="./dist/autoload.js"></script>
</body>
</html> 报错的代码是这里: // 配置选项的具体用法见 README.md
initWidget({❌ |
同样遇到问题,已经解决。 我的解决方法是在根目录下的 改完后: export default {
input: 'build/waifu-tips.js',
output: {
name: 'live2d_widget',
file: 'dist/waifu-tips.js',
format: 'iife',
},
plugins: [
nodeResolve(),
string({
include: '**/*.svg',
}),
terser(),
],
context: 'this',
}; |
@panedioic 你好,我目前也遇到了類似了,但照著你的方法將input項改為build/waifu-tips.js依然會報此問題耶 |
@whitebear13579 你也是 |
我上面的回复有一些问题。应该修改的是 你还可以修改 |
試了一下,發現 |
@whitebear13579 |
Reference to stevenjoezhang#176
我在 #175 做了完整的修正,你们可以试试看有没有解决 |
* Fix the missing initWidget See #176 * Fix the check of invalid model id See #182 --------- Co-authored-by: Mimi <[email protected]>
1.0.0-rc.2 版本已发布,欢迎试用~
|
我所做的操作是将 'live2d_path' 改为我本地的资源路径
The text was updated successfully, but these errors were encountered: