我有一个博客,有很多页面,而且一直在添加更多页面,因为它还在建设中。侧边栏经常变化,手动修改所有页面的所有侧边栏是乏味的。
我还没有学习更多关于编码的知识,我不知道如何创建可重用的组件。我在网上阅读了它并尝试了各种反应,但我所做的没有奏效。 这是侧边栏的代码:
<td class="col1">
<h3 style="font-variant: small-caps; font-weight:bold; color: #5C331B;"> Art </h3>
<p>
<a style="display: block;" href="Theodor Kittelsen.html"> Theodor Kittelsen </a>
</p>
<p>
<a style="display: block;" href="Eilif Peterssen.html"> Eilif Peterssen </a>
</p>
<p>
<a style="display: block;" href="Mikhail Nesterov.html"> Mikhail Nesterov </a>
</p>
<p>
<a style="display: block;" href="Caspar David Friedrich.html"> Caspar David Friedrich </a>
</p>
<p>
<a style="display: block;" href="Hans Thoma.html"> Hans Thoma </a>
</p>
<p>
<a style="display: block;" href="George Inness.html"> George Inness </a>
</p>
<h3 style="font-variant: small-caps; font-weight:bold; color: #5C331B;"> Poetry </h3>
<p>
<a style="display: block;" href="PERCY BYSSHE SHELLEY.html"> Percy Bysshe Shelley </a>
</p>
<p>
<a style="display: block;" href="ALGERNON CHARLES SWINBURNE.html"> Algernon Charles Swinburne </a>
</p>
<p>
<a style="display: block;" href="Rainer Maria Rilke.html"> Rainer Maria Rilke </a>
</p>
<p>
<a style="display: block;" href="LORD TENNYSON.html"> Lord Tennyson </a>
</p>
<p>
<a style="display: block;" href="Thomas Stearns Eliot.html"> Thomas Stearns Eliot </a>
</p>
<p>
<a style="display: block;" href="John Keats.html"> John Keats </a>
</p>
<p>
<a style="display: block;" href="William Wordsworth.html"> William Wordsworth </a>
</p>
<p>
<a style="display: block;" href="William Blake.html"> William Blake </a>
</p>
<p>
<a style="display: block;" href="Johann Wolfgang von Goethe.html"> Johann Wolfgang von Goethe </a>
</p>
<p>
<a style="display: block;" href="William Butler Yeats.html"> William Butler Yeats </a>
</p>
<p>
<a style="display: block;" href="Ovid.html"> Ovid </a>
</p>
<p>
<a style="display: block;" href="Mixed.html"> Mixed </a>
</p>
<h3 style="font-variant: small-caps; font-weight:bold; color: #5C331B;"> Musıc </h3>
<p>
<a style="display: block;" href="Tenhi.html"> Tenhi </a>
</p>
<p>
<a style="display: block;" href="Empyrium.html"> Empyrium </a>
</p>
<p>
<a style="display: block;" href="Ulver.html"> Ulver </a>
</p>
<p>
<a style="display: block;" href="Öröm.html"> Öröm </a>
</p>
<p>
<a style="display: block;" href="Savall.html"> Jordi & Arianna Savall </a>
</p>
<div class="box" style="background-color: #7d9ea2f4; padding: 2px; border-width: 1px; border-color: rgb(175, 164, 157); border-style: solid;">
<p>
<img src="PinIt.png" alt="Pin it button" height="20px" width="23px">
<a href="" data-pin-do="buttonPin" data-pin-shape="round">Pin this page for later</a>
</p>
<p>
<img src="envelope.png" alt="Email icon" style="margin-right: 2px; margin-bottom: 2px; height: 20px; width: 26px;">
<a href="mailto:?" data-pin-do="buttonPin" data-pin-shape="round">Email yourself this page</a>
</p>
<p>
<img src="pinterest-icon.png" alt="pinterest logo" style="margin-top: 2px; margin-right:12px; margin-bottom: 20px; height: 25px; width: 25px; float: left">
</p>
<p>
<a href="https://tr.pinterest.com/cerenntubaa/" data-pin-do="buttonPin" data-pin-shape="round">Pinterest Boards</a>
</p>
</div>
</td>
嗨,首先创建一个对象数组,将数据传递给侧边栏组件
[
{
href: ....
text: ....
}
]
然后就可以映射这个对象数组了
{dataSet.map((element, index) => {
return <p>
<a style="display: block;" href=data.html>{data.text}</a>
</p>
})}
我想这会解决你的问题