eval.rs 737 B

123456789101112131415161718192021222324252627282930313233
  1. use dioxus::prelude::*;
  2. fn main() {
  3. dioxus_desktop::launch(app);
  4. }
  5. fn app(cx: Scope) -> Element {
  6. let future = use_future(cx, (), |_| async move {
  7. let eval = eval(
  8. r#"
  9. dioxus.send("Hi from JS!");
  10. let msg = await dioxus.recv();
  11. console.log(msg);
  12. return "hello world";
  13. "#,
  14. )
  15. .unwrap();
  16. eval.send("Hi from Rust!".into()).unwrap();
  17. let res = eval.recv().await.unwrap();
  18. println!("{:?}", eval.await);
  19. res
  20. });
  21. match future.value() {
  22. Some(v) => cx.render(rsx!(
  23. p { "{v}" }
  24. )),
  25. _ => cx.render(rsx!(
  26. p { "hello" }
  27. )),
  28. }
  29. }