我一直在嘗試使用我對 Restful API 和 svelte 的知識來制作一個網路應用程式維基,我遇到了一個問題,我給超鏈接標簽指定了資料庫中每個物件的 id,它可以作業,但問題是是它繼續在瀏覽器中將超鏈接 tag() 的 id 顯示為文本。我怎樣才能解決這個問題?
這是結果的直觀表示:

這是代碼:
<script>
import { onMount } from 'svelte';
import { each } from 'svelte/internal';
import { store } from '$lib/store';
let articles = [];
onMount(async () => {
const response = await fetch('http://localhost:5000/articles');
const data = await response.json();
articles = data;
})
</script>
<div class="container">
{#each articles as article}
<a href="/articles/article/{article._id}" id={article._id}>
{article.title}
<hr>
</a>
{$store = article._id}
{/each}
</div>
<style>
a {
text-decoration: none;
color: rgb(223, 209, 209);
font-weight: bold;
font-size: 1.5rem;
}
a::hover {
text-decoration: underline;
}
div {
margin-top: 90px;
text-align: center;
}
</style>
我真的需要幫助T_T
uj5u.com熱心網友回復:
要不顯示 ID,您需要洗掉此行:
{$store = article._id}
這是分配給商店并回傳值,從而呈現 ID 文本。這在 Svelte 代碼中并不常見。通常,您更新腳本塊中的資料并在模板中呈現它——您的模板不應對您的資料產生副作用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/377699.html
標籤:javascript html 休息 苗条的 苗条的
