将app注入到所有的组件的原型链中

master 1.1.1
yutent 2023-08-16 11:03:54 +08:00
parent 285e64bbed
commit 76b3003182
2 changed files with 15 additions and 6 deletions

View File

@ -6,7 +6,7 @@
import './init.js'
import { html, css, Component } from 'wkit'
import { noop } from './utils.js'
import { noop, readonlyProp } from './utils.js'
import { __ROUTER__, __STORE__, __ROUTER_VIEW__ } from './constants.js'
export * from './router/index.js'
@ -26,12 +26,18 @@ export function createApp({
return new (function () {
App.props = data
App.styles = styles
Object.assign(App.prototype, methods, { mounted })
Object.assign(App.prototype, methods, {
mounted,
created() {
readonlyProp(Component.prototype, '$app', this)
}
})
this.use = function (plugin = noop, ...args) {
plugin.apply(App.prototype, args)
return this
}
this.mount = function () {
let $router = window.wkitd.get(__ROUTER__)
if (render) {
@ -71,6 +77,7 @@ export function createApp({
}
}
}
if ($router) {
App.prototype.mounted = function (...args) {
let $view = window.wkitd.get(__ROUTER_VIEW__)

View File

@ -9,11 +9,13 @@ const decode = decodeURIComponent
export function noop() {}
export function hideProp(host, name, value) {
export function readonlyProp(host, name, value) {
Object.defineProperty(host, name, {
value,
enumerable: false,
writable: true
get() {
return value
},
set(vale) {},
enumerable: false
})
}