dynamic_asset.rs 695 B

1234567891011121314151617181920212223242526272829
  1. use dioxus::prelude::*;
  2. use dioxus_desktop::wry::http::Response;
  3. use dioxus_desktop::{use_asset_handler, AssetRequest};
  4. use std::path::Path;
  5. fn main() {
  6. dioxus_desktop::launch(app);
  7. }
  8. fn app(cx: Scope) -> Element {
  9. use_asset_handler(cx, |request: &AssetRequest| {
  10. let path = request.path().to_path_buf();
  11. async move {
  12. if path != Path::new("logo.png") {
  13. return None;
  14. }
  15. let image_data: &[u8] = include_bytes!("./assets/logo.png");
  16. Some(Response::new(image_data.into()))
  17. }
  18. });
  19. cx.render(rsx! {
  20. div {
  21. img {
  22. src: "logo.png"
  23. }
  24. }
  25. })
  26. }