From 875514e47bd7de3683740c2b5683bc85a2f6cb05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Thu, 27 May 2021 14:02:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmd=E7=BC=96=E8=BE=91=E5=99=A8?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/meditor/addon.js | 6 ++--- src/meditor/index.wc | 54 +++++++++++++++++++------------------------- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/meditor/addon.js b/src/meditor/addon.js index 2b25b09..875cd99 100644 --- a/src/meditor/addon.js +++ b/src/meditor/addon.js @@ -128,8 +128,8 @@ export default { elem.classList.toggle('active', this.props.fullscreen) }, preview(elem) { - this.props.preview = !this.props.preview - this.__VIEW__.classList.toggle('active', this.props.preview) - elem.classList.toggle('active', this.props.preview) + this.state.preview = !this.state.preview + this.__VIEW__.classList.toggle('active', this.state.preview) + elem.classList.toggle('active', this.state.preview) } } diff --git a/src/meditor/index.wc b/src/meditor/index.wc index 48af83f..36d9df1 100644 --- a/src/meditor/index.wc +++ b/src/meditor/index.wc @@ -771,25 +771,33 @@ export default class Meditor { } } + _stat__(name, val) { + var type = typeof val + var k = name + if (k === 'readonly') { + k = 'readOnly' + } + if (val === this.props[name]) { + return + } + + if ((type === 'boolean' && val) || type !== 'boolean') { + this.props[name] = true + this.__EDITOR__[k] = true + this.setAttribute(name, '') + } else { + this.props[name] = false + this.__EDITOR__[k] = false + this.removeAttribute(name) + } + } + get readOnly() { return this.props.readonly } set readOnly(val) { - var type = typeof val - - if (val === this.props.readonly) { - return - } - if ((type === 'boolean' && val) || type !== 'boolean') { - this.props.readonly = true - this.__EDITOR__.readOnly = true - this.setAttribute('readonly', '') - } else { - this.props.readonly = false - this.__EDITOR__.readOnly = false - this.removeAttribute('readonly') - } + this.__stat__('readonly', val) } get disabled() { @@ -797,20 +805,7 @@ export default class Meditor { } set disabled(val) { - var type = typeof val - - if (val === this.props.disabled) { - return - } - if ((type === 'boolean' && val) || type !== 'boolean') { - this.props.disabled = true - this.__EDITOR__.disabled = true - this.setAttribute('disabled', '') - } else { - this.props.disabled = false - this.__EDITOR__.disabled = false - this.removeAttribute('disabled') - } + this.__stat__('disabled', val) } mounted() { @@ -1053,9 +1048,6 @@ export default class Meditor { } this[k] = val !== null break - - default: - break } } }