头图

A simple calculator written in TinyGo and compiled to WebAssembly

Live Demo

简体中文

源代码

🏀🏀A simple calculator written in TinyGo and compiled to WebAssembly🏀🏀

bilibili 在线吹水

⚽️⚽️利用Go编写WebAssembly计算器、⚽️⚽️

Features

  • ⚡️ Vue 3+Vite+pnpm, 怎么快怎么来
  • 🔎 TinyGo 追求最小打包体积
  • 🔥 wasm 玩的就是wasm
  • 🦾 Golang, of course
  • ☁️ Deploy on Netlify

snapshot

  • 挂载全局变量

const go = new Go(); // Defined in wasm_exec.js. Don't forget to add this in your index.html.

const importObject = go.importObject;
let wasmModule;

export const InitWasm = async () => {
    wasmModule = await wasmBrowserInstantiate(wasmUrl, importObject);
    go.run(wasmModule.instance);
}

export const ExpressionIt = (s) => {
    let result
    try {
        result = window.expression(s)
    } catch (e) {
        console.log(e)
        result = 'ERROR'
    }
    return result
};

  • vue端导入

(async function () {
    await InitWasm().then(() => {
        createApp(App).mount('#app');
    });
})();
  • ts支持

export function InitWasm(): Promise<void>;
export function ExpressionIt(s: string): string;

小叉Ray
0 声望1 粉丝

Rust~Golang~TypeScript~数量取胜的编程捣鼓法~