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 })