提交 3260e4bb 编写于 作者: Q qiang

chore: build

上级 734c5632
......@@ -2945,23 +2945,6 @@ const handleWrap = function (mp, destory) {
};
function parseApp (vm) {
Object.defineProperty(Vue.prototype, '$slots', {
get () {
return this.$scope && this.$scope.props.$slots
},
set () {
}
});
Object.defineProperty(Vue.prototype, '$scopedSlots', {
get () {
return this.$scope && this.$scope.props.$scopedSlots
},
set () {
}
});
Vue.prototype.$onAliGetAuthorize = function onAliGetAuthorize (method, $event) {
my.getPhoneNumber({
success: (res) => {
......@@ -3129,6 +3112,29 @@ function createPage (vuePageOptions) {
}
}
function initSlots (vm, vueSlots) {
const $slots = Object.create(null);
// 未启用小程序基础库 2.0 时,组件实例支持支持访问 $slots、$scopedSlots
Object.defineProperty(vm, '$slots', {
get () {
const $scope = this.$scope;
return ($scope && $scope.props.$slots) || ($scope && $scope.props.$scopedSlots ? {} : $slots)
}
});
Object.defineProperty(vm, '$scopedSlots', {
get () {
const $scope = this.$scope;
return ($scope && $scope.props.$scopedSlots) || ($scope && $scope.props.$slots ? {} : $slots)
}
});
// 处理$slots,$scopedSlots(暂不支持动态变化$slots)
if (Array.isArray(vueSlots) && vueSlots.length) {
vueSlots.forEach(slotName => {
$slots[slotName] = true;
});
}
}
function initVm (VueComponent) {
if (this.$vm) {
return
......@@ -3153,6 +3159,8 @@ function initVm (VueComponent) {
// 初始化 vue 实例
this.$vm = new VueComponent(options);
initSlots(this.$vm, properties.vueSlots);
// 触发首次 setData
this.$vm.$mount();
} else {
......@@ -3168,6 +3176,9 @@ function initVm (VueComponent) {
// 初始化 vue 实例
this.$vm = new VueComponent(options);
handleRef.call(options.parent.$scope, this);
initSlots(this.$vm, properties.vueSlots);
// 触发首次 setData
this.$vm.$mount();
......@@ -3190,9 +3201,7 @@ function parseComponent (vueComponentOptions) {
};
Object.keys(properties).forEach(key => {
if (key !== 'vueSlots') {
props[key] = properties[key].value;
}
props[key] = properties[key].value;
});
const componentOptions = {
......
......@@ -2381,12 +2381,13 @@ function initRefs (vm) {
Object.defineProperty(vm, '$refs', {
get () {
const $refs = {};
const components = mpInstance.selectAllComponents('.vue-ref');
// mpInstance 销毁后 selectAllComponents 取值为 null
const components = mpInstance.selectAllComponents('.vue-ref') || [];
components.forEach(component => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
});
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for') || [];
forComponents.forEach(component => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
......@@ -2694,7 +2695,11 @@ function parseComponent (vueOptions) {
});
};
const oldDetached = lifetimes.detached;
lifetimes.detached = function detached () {
if (typeof oldDetached === 'function') {
oldDetached.call(this);
}
currentComponents(this, components => {
const index = components.indexOf(this);
if (index >= 0) {
......@@ -2773,7 +2778,6 @@ function parsePage (vuePageOptions) {
if (typeof oldDetached === 'function') {
oldDetached.call(this);
}
this.$vm && this.$vm.$destroy();
// 清理
const webviewId = this.__webviewId__;
webviewId && Object.keys(instances).forEach(key => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册