Complete Vue.js 2 Web Development_ Practical guide to building end-to-end web development solutions with Vue.js 2

(singke) #1
Building an E-Commerce Store - Adding a Checkout Chapter 11

The next step is to create a submit method and collate the data to be able to pass it on to


the next screen. Create a new method titled submitForm(). As we are not handling


payment in this example, we can route to the confirmation page in the method:


methods: {
submitForm() {
// this.billing = billing details
// this.delivery = delivery details
this.$router.push({name: 'Confirmation'});
}
}

We can now bind a submit event to the form and add a submit button. Like the v-


bind:click attribute (or @click), Vue allows you to bind a submit event to a method


using a @submit="" attribute.


Add the declaration to the

element and create a submit button in your form:


<form @submit="submitForm()">
<fieldset>

</fieldset>

<fieldset>

</fieldset>

<input type="submit" value="Purchase items">
</form>

On submitting your form, the app should redirect you to our Confirmation page.


Copying details between addresses


One feature that several shops have is the ability to mark the delivery address to be the
same as the billing address. There are several ways we could approach this, and how you


choose to do it is up to you. The immediate options are:


Have a "copy details" button—this copies the details from billing to delivery but
does not keep them in sync
Free download pdf