feat: add local storage for custom style

添加本地存储
This commit is contained in:
yanglbme 2020-01-06 20:35:41 +08:00
parent caccd837ec
commit 305cc4af27

View File

@ -38,6 +38,10 @@ let app = new Vue({
return d; return d;
}, },
mounted() { 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.showBox = false
this.editor = CodeMirror.fromTextArea( this.editor = CodeMirror.fromTextArea(
document.getElementById('editor'), document.getElementById('editor'),
@ -137,6 +141,7 @@ let app = new Vue({
fonts: fonts fonts: fonts
}); });
this.currentFont = fonts; this.currentFont = fonts;
localStorage.setItem('fonts', fonts);
this.refresh(); this.refresh();
}, },
sizeChanged(size) { sizeChanged(size) {
@ -149,6 +154,7 @@ let app = new Vue({
theme: theme theme: theme
}); });
this.currentSize = size; this.currentSize = size;
localStorage.setItem('size', size);
this.refresh(); this.refresh();
}, },
colorChanged(color) { colorChanged(color) {
@ -158,6 +164,7 @@ let app = new Vue({
theme: theme theme: theme
}); });
this.currentColor = color; this.currentColor = color;
localStorage.setItem('color', color);
this.refresh(); this.refresh();
}, },
cssChanged() { cssChanged() {
@ -239,6 +246,10 @@ let app = new Vue({
this.editor.setValue(DEFAULT_CONTENT); this.editor.setValue(DEFAULT_CONTENT);
this.cssEditor.setValue(DEFAULT_CSS_CONTENT); this.cssEditor.setValue(DEFAULT_CSS_CONTENT);
this.editor.focus(); 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() this.cssChanged()
}).catch(() => { }).catch(() => {
this.editor.focus(); this.editor.focus();
@ -271,6 +282,7 @@ let app = new Vue({
this.refresh(); this.refresh();
}, },
statusChanged() { statusChanged() {
localStorage.setItem('status', this.status);
this.refresh(); this.refresh();
}, },
// 将编辑器内容保存到 LocalStorage // 将编辑器内容保存到 LocalStorage