Skip to content

Fix code style in Client-Side Storage recipe #1690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions src/v2/cookbook/client-side-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand All @@ -106,7 +112,7 @@ As mentioned above, Local Storage only works with simple values. To store more c
<h2>Cats</h2>
<div v-for="(cat,n) in cats">
<p>
<span class="cat">{{cat}}</span> <button @click="removeCat(n)">Remove</button>
<span class="cat">{{ cat }}</span> <button @click="removeCat(n)">Remove</button>
</p>
</div>

Expand All @@ -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) {
Expand All @@ -140,13 +146,16 @@ const app = new Vue({
methods: {
addCat() {
// ensure they actually typed something
if(!this.newCat) return;
if (!this.newCat) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this one needs to be fixed this way, maybe @chrisvfritz can sound off on it

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() {
Expand Down