[英]Vue 3 form submission doing Get request instead of Post
我在 1337 使用我的节点服务器,但我的 vue.js 项目正在给出一个 get 请求而不是 post 请求,下面是我的 vue 3 代码。 问题是节点服务器还是 vue 项目出现的问题,有人可以解释一下吗?
<template>
<div>
<h1>Register</h1>
<form @submit.prevent="handlesubmit" method="post" >
<input type="text" placeholder="name" v-model="name">
<br>
<input type="email" placeholder="email" v-model="email"><br>
<input type="password" placeholder="password" v-model="password"><br>
<input type="submit" value="register" formmethod="post">
</form>
<router-view />
</div>
</template>
<script>
import { ref } from "vue"
export default {
setup(){
const name = ref("")
const email = ref("")
const password = ref("")
const handlesubmit = async () => {
console.log("name:", name.value)
console.log("email:", email.value)
console.log("password:", password.value)
const register = {
name: name.value,
email: email.value,
password: password.value
}
await fetch("http://localhost:1337/api/register"),{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(register)
}
}
return {handlesubmit}
}
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.