1 Star 0 Fork 0

张牧歌 / 小程序开发前准备demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Init.js 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
张强 提交于 2019-05-13 02:08 . component demo
import _util from "./Util";
import _fetch from "./Fetch";
import _router from './Router'
let originPage = Page;
let originComponent = Component;
Page = (opt) => {
opt = {
...opt,
_util,
_fetch,
_router
}
return originPage(opt);
}
Component = (opt) => {
let { props = {} } = opt;
let properties = {};
// 优化 properties 传入方式
Object.keys(props).forEach(item => {
properties[item] = {
type: _util.getValueType(props[item]),
value: props[item],
observer: function (newVal, oldVal, changedPath) {
const changeEvent = {
event: item,
newVal, oldVal, changedPath
};
// 传入属性可通过组件内定义的$watch方法统一监听变化
this.$watch && this.$watch(changeEvent);
}
}
});
opt.properties = properties;
// Component函数的options无法传入参数 只能在某个生命周期函数被调用时动态赋值
let originAttached = opt.attached || function () {};
opt.attached = function() {
this._util = _util;
this._fetch = _fetch;
this._router = _router;
return originAttached.apply(this);
}
return originComponent(opt)
}
JavaScript
1
https://gitee.com/hadron/mp-demo.git
git@gitee.com:hadron/mp-demo.git
hadron
mp-demo
小程序开发前准备demo
master

搜索帮助