Skip to content

Commit

Permalink
feat: add local storage for custom style
Browse files Browse the repository at this point in the history
添加本地存储
  • Loading branch information
yanglbme committed Jan 6, 2020
1 parent caccd83 commit 305cc4a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions assets/scripts/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ let app = new Vue({
return d;
},
mounted() {
this.currentFont = localStorage.getItem('fonts') || this.builtinFonts[0].value;
this.currentColor = localStorage.getItem('color') || this.colorOption[1].value;
this.currentSize = localStorage.getItem('size') || this.sizeOption[2].value;
this.status = localStorage.getItem('status') === 'true';
this.showBox = false
this.editor = CodeMirror.fromTextArea(
document.getElementById('editor'),
Expand Down Expand Up @@ -137,6 +141,7 @@ let app = new Vue({
fonts: fonts
});
this.currentFont = fonts;
localStorage.setItem('fonts', fonts);
this.refresh();
},
sizeChanged(size) {
Expand All @@ -149,6 +154,7 @@ let app = new Vue({
theme: theme
});
this.currentSize = size;
localStorage.setItem('size', size);
this.refresh();
},
colorChanged(color) {
Expand All @@ -158,6 +164,7 @@ let app = new Vue({
theme: theme
});
this.currentColor = color;
localStorage.setItem('color', color);
this.refresh();
},
cssChanged() {
Expand Down Expand Up @@ -239,6 +246,10 @@ let app = new Vue({
this.editor.setValue(DEFAULT_CONTENT);
this.cssEditor.setValue(DEFAULT_CSS_CONTENT);
this.editor.focus();
this.currentFont = this.builtinFonts[0].value;
this.currentColor = this.colorOption[1].value;
this.currentSize = this.sizeOption[2].value;
this.status = '1';
this.cssChanged()
}).catch(() => {
this.editor.focus();
Expand Down Expand Up @@ -271,6 +282,7 @@ let app = new Vue({
this.refresh();
},
statusChanged() {
localStorage.setItem('status', this.status);
this.refresh();
},
// 将编辑器内容保存到 LocalStorage
Expand Down

0 comments on commit 305cc4a

Please sign in to comment.