我想添加一個類名到元素,但它不工作。我是否錯過了JSX組件?反應添加類到元素
import { h, Component } from 'preact';
import { Link } from 'preact-router/match';
import style from './style';
export default class Header extends Component {
render() {
return (
<header class={style.header}>
<h1>Lancaster County Apple Corps</h1>
<img class="site-icon" src="assets/icons/icon-128x128.png" alt="LCAC site icon" />
<nav>
<Link activeClassName={style.active} href="/">Home</Link>
<Link activeClassName={style.active} href="/benefits">Benefits</Link>
<Link activeClassName={style.active} href="/cost">Cost</Link>
<Link activeClassName={style.active} href="/memberForm">Member Form</Link>
<Link activeClassName={style.active} href="/meetingNotes">Meeting Notes</Link>
<Link activeClassName={style.active} href="/links">Links</Link>
</nav>
</header>
);
}
}
是的,您必須使用'className'來設置HTML的'class'屬性。 –