From 305cc4af27a7dc4d71a246d5ad514c8d2ef93c7e Mon Sep 17 00:00:00 2001 From: yanglbme Date: Mon, 6 Jan 2020 20:35:41 +0800 Subject: [PATCH] feat: add local storage for custom style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加本地存储 --- assets/scripts/editor.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/assets/scripts/editor.js b/assets/scripts/editor.js index f5aaee6..47677f5 100644 --- a/assets/scripts/editor.js +++ b/assets/scripts/editor.js @@ -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'), @@ -137,6 +141,7 @@ let app = new Vue({ fonts: fonts }); this.currentFont = fonts; + localStorage.setItem('fonts', fonts); this.refresh(); }, sizeChanged(size) { @@ -149,6 +154,7 @@ let app = new Vue({ theme: theme }); this.currentSize = size; + localStorage.setItem('size', size); this.refresh(); }, colorChanged(color) { @@ -158,6 +164,7 @@ let app = new Vue({ theme: theme }); this.currentColor = color; + localStorage.setItem('color', color); this.refresh(); }, cssChanged() { @@ -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(); @@ -271,6 +282,7 @@ let app = new Vue({ this.refresh(); }, statusChanged() { + localStorage.setItem('status', this.status); this.refresh(); }, // 将编辑器内容保存到 LocalStorage