0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Leptosでimg要素を使って画像を表示したい

0
Posted at

メモレベルの内容ですので正確性に欠けるところがあるかもしれません。
必要のない設定などがある可能性があることをご了承ください。
とりあえずこれで動作は確認しています。

動作確認をしているLeptosのバージョンは「0.8.15」です。

イメージの配置場所

「プロジェクト/public」配下に配置します。

image1.jpg

設定の追加

Cargo.tomlに以下を追加

[package]
name = "leptos-web"
version = "0.1.0"
edition = "2024"

+ [package.metadata.leptos]
+ assets-dir = "public"

[dependencies]
leptos = {version = "0.8.15", features = ["csr"]}

index.htmlに以下を追加

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
+   <link data-trunk rel="copy-dir" href="/public/images"/>
    <title>web-site</title>
</head>

Rustのコーディング

#[component]
fn DisplayImage() -> impl IntoView {
    view! {
        <img src="/images/site-icon.png" />
    }
}

以上で画像を画面に表示することができました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?