dynamic_asset.rs 650 B

12345678910111213141516171819202122232425
  1. use dioxus::prelude::*;
  2. use dioxus_desktop::{use_asset_handler, wry::http::Response};
  3. fn main() {
  4. launch_desktop(app);
  5. }
  6. fn app() -> Element {
  7. use_asset_handler("logos", |request, response| {
  8. // Note that the "logos" prefix is stripped from the URI
  9. //
  10. // However, the asset is absolute to its "virtual folder" - meaning it starts with a leading slash
  11. if request.uri().path() != "/logo.png" {
  12. return;
  13. }
  14. response.respond(Response::new(include_bytes!("./assets/logo.png").to_vec()));
  15. });
  16. render! {
  17. div {
  18. img { src: "/logos/logo.png" }
  19. }
  20. }
  21. }