We will create this page to communicate with the server-side POST route, /api/user/, to add a new user in the following steps:
- Create a form to collect the new user data in the <template> block as follows:
// pages/users/add/index.vue
<form v-on:submit.prevent="add">
<p>Name: <input v-model="name" type="text" name="name"></p>
<p>Slug: <input v-model="slug" type="text" name="slug"></p>
<button type="submit">Add</button>
<button v-on:click="cancel">Cancel</button>
</form>
- Create an add method to send the data to the server and a cancel method to cancel the form in the <script> block as follows:
// pages/users/add/index.vue
export default {
methods: {
async add () {
let { data } = await axios.post('/api/user/', {
name: this.name,
slug: this...