From e782d9cf96295e169187a99f95a2b743a2cbae8a Mon Sep 17 00:00:00 2001 From: yutent Date: Mon, 14 Aug 2023 22:20:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=8A=E5=85=A8=E5=B1=80=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=8F=AA=E8=AF=BB=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/init.js | 13 +++++++++++-- src/router/index.js | 10 +++++++++- src/store.js | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/init.js b/src/init.js index acda3ec..c1771de 100644 --- a/src/init.js +++ b/src/init.js @@ -4,6 +4,15 @@ * @date 2023/08/10 10:19:12 */ -import { hideProp } from './utils.js' +const __WKITD__ = new Map() -hideProp(window, '__wkitd__', new Map()) +Object.defineProperty(window, '__wkitd__', { + get() { + return __WKITD__ + }, + set(val) { + console.error('Can not set readonly property __wkitd__ of window') + }, + writable: false, + enumerable: false +}) diff --git a/src/router/index.js b/src/router/index.js index 6102cb1..9cfbbf9 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -19,7 +19,15 @@ export function createRouter({ $router.addRoute(routes) function wrapper() { - Component.prototype.$router = $router + Object.defineProperty(Component.prototype, '$router', { + get() { + return window.__wkitd__.get('$router') + }, + set(val) { + console.error('Can not set readonly property $router of Component') + }, + enumerable: false + }) } wrapper.beforeEach = $router.beforeEach.bind($router) return wrapper diff --git a/src/store.js b/src/store.js index abb0ccd..576f874 100644 --- a/src/store.js +++ b/src/store.js @@ -23,7 +23,7 @@ export function createStore(obj = {}) { return window.__wkitd__.get('$store') }, set(val) { - console.error('Can not replace readonly property $store of Component') + console.error('Can not set readonly property $store of Component') }, enumerable: false })