In this post we are going to look at POST requests in Nuxt 3. This is something that should be really simple to do, and to be honest with you it is. However if you are a moron like me you might find yourself spending two days trying to figure it out. In this post I'll go over everything you need to get POST requests working in Nuxt 3. I'll over go over some of the issues I encountered when trying to figure out how to make it work, and the solutions. I'll even go over fixing CORS issues! You're welcome. Feel free to follow along with the video, or checkout the detailed instructions below.
If you are already setup with an existing Nuxt 3 project you can skip this step. If you haven't already got a Nuxt 3 project set up, go ahead and do this. Instructions on how to do this can be found in the nuxt documentation but its just a case of running the following commands:
npx nuxi init
Once you have run this command, navigate into your newly created project, install it, and start the development server. Like this:
cd
npm install
npm run dev -- -o
You now have your Nuxt 3 project setup and ready to go!
In our Nuxt 3 project we are going to create a form. This form is where we are going to submit our POST request from.
Within our template tags, we can create our form. Create your form with whatever inputs you require. For our form we will have the inputs: 'name', 'email' and 'message'. We will bind these to a formData object using v-model. Checkout the code below and make sure you have something similar. Please note, I have removed some of the markup that you see in the video to make it easier to see what's going on, and also because I am using tailwindcss classes in the video which you don't need.
Nicely designed Loft Conversion websites
The best looking loft conversion websites I could find on the internet
ReplyGuy an idiots first impression
Are you looking for a way to automate your marketing efforts? Do you like new, and innovative technology? Well, maybe you will enjoy using ReplyGuy. I gave it a go to see what all the fuss if about