Skip to content

Commit 779c5d5

Browse files
lex111sdras
authored andcommitted
Fix code style in Client-Side Storage recipe (#1690)
1 parent 171e198 commit 779c5d5

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/v2/cookbook/client-side-storage.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ This example has one form field bound to a Vue value called `name`. Here's the J
2222

2323
``` js
2424
const app = new Vue({
25-
el:'#app',
25+
el: '#app',
2626
data: {
27-
name:''
27+
name: ''
2828
},
2929
mounted() {
30-
if(localStorage.name) this.name = localStorage.name;
30+
if (localStorage.name) {
31+
this.name = localStorage.name;
32+
}
3133
},
3234
watch: {
3335
name(newName) {
@@ -75,12 +77,16 @@ Now we've got two fields (again, bound to a Vue instance) but now there is the a
7577
const app = new Vue({
7678
el:'#app',
7779
data: {
78-
name:'',
79-
age:0
80+
name: '',
81+
age: 0
8082
},
8183
mounted() {
82-
if(localStorage.name) this.name = localStorage.name;
83-
if(localStorage.age) this.age = localStorage.age;
84+
if (localStorage.name) {
85+
this.name = localStorage.name;
86+
}
87+
if (localStorage.age) {
88+
this.age = localStorage.age;
89+
}
8490
},
8591
methods: {
8692
persist() {
@@ -106,7 +112,7 @@ As mentioned above, Local Storage only works with simple values. To store more c
106112
<h2>Cats</h2>
107113
<div v-for="(cat,n) in cats">
108114
<p>
109-
<span class="cat">{{cat}}</span> <button @click="removeCat(n)">Remove</button>
115+
<span class="cat">{{ cat }}</span> <button @click="removeCat(n)">Remove</button>
110116
</p>
111117
</div>
112118

@@ -122,14 +128,14 @@ This "app" consists of a simple list on top (with a button to remove a cat) and
122128

123129
``` js
124130
const app = new Vue({
125-
el:'#app',
131+
el: '#app',
126132
data: {
127-
cats:[],
128-
newCat:null
133+
cats: [],
134+
newCat: null
129135
},
130136
mounted() {
131137

132-
if(localStorage.getItem('cats')) {
138+
if (localStorage.getItem('cats')) {
133139
try {
134140
this.cats = JSON.parse(localStorage.getItem('cats'));
135141
} catch(e) {
@@ -140,13 +146,16 @@ const app = new Vue({
140146
methods: {
141147
addCat() {
142148
// ensure they actually typed something
143-
if(!this.newCat) return;
149+
if (!this.newCat) {
150+
return;
151+
}
152+
144153
this.cats.push(this.newCat);
145154
this.newCat = '';
146155
this.saveCats();
147156
},
148157
removeCat(x) {
149-
this.cats.splice(x,1);
158+
this.cats.splice(x, 1);
150159
this.saveCats();
151160
},
152161
saveCats() {

0 commit comments

Comments
 (0)