把全局对象改为只读模式
parent
409ba1905e
commit
e782d9cf96
13
src/init.js
13
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
|
||||
})
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue