mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-26 14:10:20 +00:00
add a dynamic asset example
This commit is contained in:
parent
7649ad84a1
commit
9eee4ab8f8
1 changed files with 29 additions and 0 deletions
29
examples/dynamic_asset.rs
Normal file
29
examples/dynamic_asset.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
use dioxus::prelude::*;
|
||||
use dioxus_desktop::wry::http::Response;
|
||||
use dioxus_desktop::{use_asset_handler, AssetRequest};
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
dioxus_desktop::launch(app);
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
use_asset_handler(cx, |request: &AssetRequest| {
|
||||
let path = request.path().to_path_buf();
|
||||
async move {
|
||||
if path != Path::new("logo.png") {
|
||||
return None;
|
||||
}
|
||||
let image_data: &[u8] = include_bytes!("./assets/logo.png");
|
||||
Some(Response::new(image_data.into()))
|
||||
}
|
||||
});
|
||||
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
img {
|
||||
src: "logo.png"
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue