From 76b3003182f63a53fb6987922bdcb7d470274eda Mon Sep 17 00:00:00 2001 From: yutent Date: Wed, 16 Aug 2023 11:03:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86app=E6=B3=A8=E5=85=A5=E5=88=B0?= =?UTF-8?q?=E6=89=80=E6=9C=89=E7=9A=84=E7=BB=84=E4=BB=B6=E7=9A=84=E5=8E=9F?= =?UTF-8?q?=E5=9E=8B=E9=93=BE=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 11 +++++++++-- src/utils.js | 10 ++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index 9b12812..7a13c17 100644 --- a/src/index.js +++ b/src/index.js @@ -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__) diff --git a/src/utils.js b/src/utils.js index f509c90..ef155ca 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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 }) }