Reader small image

You're reading from  Vue.js 2.x by Example

Product typeBook
Published inDec 2017
Reading LevelBeginner
PublisherPackt
ISBN-139781788293464
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Mike Street
Mike Street
author image
Mike Street

Mike Street (aka mikestreety) is a frontend developer from Brighton, UK. Specializing in Gulp, SCSS, HTML, and Vue, he has been developing websites professionally since 2010. After making his first Vue app as an experimental side project, he's been hooked ever since. When not developing on the web, Mike likes to explore the Sussex countryside on his bike, start a new side-project without finishing the last, or heading to the cinema.
Read more about Mike Street

Right arrow

Updating the Add to basket button when adding an item

As a usability improvement to our shop, we are going to update the Add to basket button when a user clicks it. This will change to Added to your basket and apply a class for a set period of time, for example, two seconds, before returning to its previous state. The CSS class will allow you to style the button differently—for example, changing the background to green or transforming it slightly.

This will be achieved by using a data property on the component—setting it to true and false as the item gets added. The CSS class and text will use this property to determine what to show and a setTimeout JavaScript function will change the state of the property.

Open the ProductPage component and add a new key to the data object titled addedToBasket. Set this to false by default:

data() {
return {
slug: this.$route...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Vue.js 2.x by Example
Published in: Dec 2017Publisher: PacktISBN-13: 9781788293464

Author (1)

author image
Mike Street

Mike Street (aka mikestreety) is a frontend developer from Brighton, UK. Specializing in Gulp, SCSS, HTML, and Vue, he has been developing websites professionally since 2010. After making his first Vue app as an experimental side project, he's been hooked ever since. When not developing on the web, Mike likes to explore the Sussex countryside on his bike, start a new side-project without finishing the last, or heading to the cinema.
Read more about Mike Street