javascript - WebAssembly 代码未在现有 angularjs 应用程序中运行
问题描述
我已经在 rust 和 webAssembly 中编写了代码并在其中玩弄,我遇到了一些问题。
lib.rs文件
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern {
pub fn alert(s: &str);
}
#[wasm_bindgen]
pub fn greet(name: &str) {
alert(&format!("Hello, {}!", name));
}
使用cargo将上述文件构建到wasm并部署到 NPM 注册表。 https://www.npmjs.com/package/@livspace-3d/hello-wasm
现在,我已经将相同的 npm 模块安装到我的应用程序中,使用npm i <package_name>
在 index.html 代码中使用 wasm 文件时出错,代码如下:
<script>
function fetchAndInstantiate() {
fetch('./static/js/hello-wasm/pkg/hello_wasm_bg.wasm').then(response =>
response.arrayBuffer()
).then(bytes =>{
console.error("I am herer2", JSON.stringify(bytes));
return WebAssembly.compile(bytes)
}).then(mod =>{
console.error("I am herer3", mod);
mod.greet("WebAssembly");
});
}
fetchAndInstantiate();
<script>
控制台打印:
解决方案
推荐阅读
- c++ - Ubuntu 中的键盘事件不起作用?
- github - 提交并推送到 GitHub 存储库后 Pycharm 中的 ModuleNotFoundError
- python - 如何在 Pandas 中获取并行行值?
- java - Java - 检查 under_score 字符串是否在 lowerCamel 字符串列表中
- godot - 编辑器中设置的导出值在代码中显示为零
- tailwind-css - 我如何使 2 列在 tailwind.css 中独立运行
- react-native - React Native:警告:道具类型失败:提供给`MapMarker`的`number`类型的无效道具`coordinate`,预期`object`
- css - 内联 CSS 语法。如何将名为 image.jpg 的图像放置在左侧 10 像素和顶部 10 像素的绝对位置
- autodesk-forge - Revit Core Engine Core Console 因处理时间限制而关闭
- kubernetes - 如何在 Rancher-Kubernetes 上设置 Airflow