From c3db767468342bfd9cf6273ac248241d3d3e9453 Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Sat, 16 Jun 2018 21:14:09 +0300 Subject: [PATCH] Fix code style in Client-Side Storage recipe --- src/v2/cookbook/client-side-storage.md | 37 ++++++++++++++++---------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/v2/cookbook/client-side-storage.md b/src/v2/cookbook/client-side-storage.md index ffeb70fb77..364e67dbbc 100644 --- a/src/v2/cookbook/client-side-storage.md +++ b/src/v2/cookbook/client-side-storage.md @@ -22,12 +22,14 @@ This example has one form field bound to a Vue value called `name`. Here's the J ``` js const app = new Vue({ - el:'#app', + el: '#app', data: { - name:'' + name: '' }, mounted() { - if(localStorage.name) this.name = localStorage.name; + if (localStorage.name) { + this.name = localStorage.name; + } }, watch: { name(newName) { @@ -75,12 +77,16 @@ Now we've got two fields (again, bound to a Vue instance) but now there is the a const app = new Vue({ el:'#app', data: { - name:'', - age:0 + name: '', + age: 0 }, mounted() { - if(localStorage.name) this.name = localStorage.name; - if(localStorage.age) this.age = localStorage.age; + if (localStorage.name) { + this.name = localStorage.name; + } + if (localStorage.age) { + this.age = localStorage.age; + } }, methods: { persist() { @@ -106,7 +112,7 @@ As mentioned above, Local Storage only works with simple values. To store more c

Cats

- {{cat}} + {{ cat }}

@@ -122,14 +128,14 @@ This "app" consists of a simple list on top (with a button to remove a cat) and ``` js const app = new Vue({ - el:'#app', + el: '#app', data: { - cats:[], - newCat:null + cats: [], + newCat: null }, mounted() { - if(localStorage.getItem('cats')) { + if (localStorage.getItem('cats')) { try { this.cats = JSON.parse(localStorage.getItem('cats')); } catch(e) { @@ -140,13 +146,16 @@ const app = new Vue({ methods: { addCat() { // ensure they actually typed something - if(!this.newCat) return; + if (!this.newCat) { + return; + } + this.cats.push(this.newCat); this.newCat = ''; this.saveCats(); }, removeCat(x) { - this.cats.splice(x,1); + this.cats.splice(x, 1); this.saveCats(); }, saveCats() {