我正在使用Reactjs和Nextjs框架,现在我正在管理面板上工作,并尝试更新用户配置文件,为此,我创建了文件“[profile.js]”并传递userId,我尝试在表单内获取用户信息,并希望更新表单意味着每当用户点击“更新”时,信息应通过Axios更新(API已经创建),但是我如何使用“form submit”?换句话说,我如何在nextjs中获得form/use函数的值?以下是我当前的代码
const Post = ({ post }) => {
// want to get form data and .....further code
}
return (
<>
<form className="forms-sample" >
<input
type="text"
className="form-control"
id="exampleInputName1"
placeholder="Title"
name="name"
value={Post.title}/> //not showing
<button type="submit" className='btn btn-primary mr-2'>Submit</button>
</form>
</>
);
export const getStaticProps = async ({ params }) => {
const { data } = await Axios.get(`xxxxxxxxxxxxxxxxxxxxxx/getblogbyuserid/${params.slug}`);
const post = data;
return {
props: {
post,
},
};
};
export const getStaticPaths = async () => {
const { data } = await Axios.get("xxxxxxxxxxxxxxxxxxxxxxxxxxxx/api/blogs");
const posts = data.slice(0, 10);
const paths = posts.map((post) => ({ params: { slug: post.id.toString() } }));
return {
paths,
fallback: true,
};
};
1条答案
按热度按时间kyvafyod1#
你可以这样做: