博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Yew 初尝试
阅读量:4046 次
发布时间:2019-05-24

本文共 1481 字,大约阅读时间需要 4 分钟。

WebAssembly 借助 LLVM 可以支持多种语言混合开发,安全性极高,性能也有所提升。本文使用 WebAssembly 支持最好的语言,也是未来最有潜力的语言,即 Rust 的主流框架 Yew 入门 wasm H5 开发。

Yew 开发类似 Vue、React。本文代码 https://github.com/tothis/rust-record/tree/main/yew

index.html

    
index

Cargo.toml

[package]name = "yew-record"version = "0.1.0"authors = ["Li Lei 
"]edition = "2018"[dependencies]yew = "0.18"wasm-bindgen = "0.2"

src/main.rs

use wasm_bindgen::JsValue;use yew::{Component, ComponentLink, Html, html, ShouldRender};use yew::web_sys::console::log_1;enum Action {    AddOne,}struct Model {    link: ComponentLink
, value: i64,}impl Component for Model { type Message = Action; type Properties = (); fn create(_props: Self::Properties, link: ComponentLink
) -> Self { Self { link, value: 0, } } fn update(&mut self, m: Self::Message) -> ShouldRender { match m { Action::AddOne => { self.value += 1; log_1(&JsValue::from_str(&self.value.to_string())); // 重新渲染组件 true } } } fn change(&mut self, _props: Self::Properties) -> ShouldRender { false } fn view(&self) -> Html { html! { <>

{ self.value }

} }}fn main() { yew::start_app::
();}

启动

cargo install wasm-bindgen# 使用 trunk# 安装cargo install trunk wasm-bindgen-cli# 启动trunk serve

转载地址:http://ufwci.baihongyu.com/

你可能感兴趣的文章
Js作用域与作用域链详解
查看>>
nginx下 499错误
查看>>
网络性能测试工具iperf详细使用图文教程
查看>>
MacOSX上ab并发测试常见报错及解决办法
查看>>
为你的网站开启 gzip 压缩功能(nodejs、nginx)
查看>>
网页性能管理详解
查看>>
try catch 对代码运行的性能影响
查看>>
Koa框架实践与中间件原理剖析
查看>>
node.js 资料收集
查看>>
解除 Linux 系统的最大进程数和最大文件打开数限制
查看>>
怎样才是一个基本水平的java程序员?
查看>>
UGC,PGC,OGC
查看>>
一道关于Promise应用的面试题
查看>>
Couchbase 介绍 - 更好的 Cache 系统
查看>>
Memcached Redis Membase性能测试对比分析
查看>>
couchbase 与 redis的横向对比
查看>>
缓存的进化之路—Couchbase的分布式架构
查看>>
Chrome渲染分析之Timeline工具的使用
查看>>
浏览器加载 CommonJS 模块的原理与实现
查看>>
Node.js框架之express与koa对比分析
查看>>