【发布时间】:2021-08-21 09:32:50
【问题描述】:
我想基于输入搜索。
能够将内容发送到另一个页面,然后该页面使用输入搜索的内容发出 API 请求。
基本上,我希望用户能够使用搜索栏,输入“某物”,然后这个“某物”可以用来发出 API 请求。
我的文件:
- index.js
- search
- q.js
index.js:
...
form action="./search/q" method="get">
<button type="submit">
<i class="fas fa-search fa-2x"></i>
</button>
<input type="text" placeholder="Search" id="query" name="serach" />
</form>
q.js:
import Head from "next/head";
export default function Home({ articles }) {
return (
<>
<Head>
<title>Test</title>
</Head>
<main class="container">...</main>
</>
);
}
export async function getStaticProps() {
const articles = await fetch(`...${query}`).then((r) => r.json());
return {
props: {
articles,
},
};
}
【问题讨论】:
标签: javascript html next.js