面试题答案
一键面试import { createSignal } from 'solid-js';
const [isLoggedIn, setIsLoggedIn] = createSignal(false);
// 模拟登录逻辑
const handleLogin = () => {
setIsLoggedIn(true);
};
// 模拟登出逻辑
const handleLogout = () => {
setIsLoggedIn(false);
};
const App = () => {
return (
<div>
{isLoggedIn() ? (
<>
<p>欢迎您!</p>
<button onClick={handleLogout}>登出</button>
</>
) : (
<>
<button onClick={handleLogin}>登录</button>
<button>注册</button>
</>
)}
</div>
);
};
export default App;