'Vue 3 form submission doing Get request instead of Post
I am using my node server at 1337 but my vue.js project is giving a get request instead of post request below is my vue 3 code. is the problem occuring from node server or the vue project can someone please explain the issue?
<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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|