提交 bc0a4d43 编写于 作者: fxy060608's avatar fxy060608

fix(mp-weixin): properties default value

上级 35d77e03
......@@ -5043,7 +5043,8 @@ var serviceContext = (function (vue) {
current: {
type: [Number, String],
},
};
};
const API_CLOSE_PREVIEW_IMAGE = 'closePreviewImage';
const API_GET_VIDEO_INFO = 'getVideoInfo';
const GetVideoInfoOptions = {
......@@ -7499,7 +7500,17 @@ var serviceContext = (function (vue) {
},
});
resolve();
}, PreviewImageProtocol, PreviewImageOptions);
}, PreviewImageProtocol, PreviewImageOptions);
const closePreviewImage = defineAsyncApi(API_CLOSE_PREVIEW_IMAGE, (_, { resolve, reject }) => {
try {
// @ts-expect-error
plus.nativeUI.closePreviewImage();
resolve();
}
catch (error) {
reject();
}
});
let recorder;
let recording = false;
......@@ -12904,6 +12915,7 @@ var serviceContext = (function (vue) {
getImageInfo: getImageInfo,
getVideoInfo: getVideoInfo,
previewImage: previewImage,
closePreviewImage: closePreviewImage,
getRecorderManager: getRecorderManager,
saveVideoToPhotosAlbum: saveVideoToPhotosAlbum,
saveImageToPhotosAlbum: saveImageToPhotosAlbum,
......
......@@ -4783,6 +4783,7 @@ const PreviewImageProtocol = {
type: [Number, String]
}
};
const API_CLOSE_PREVIEW_IMAGE = "closePreviewImage";
const API_GET_VIDEO_INFO = "getVideoInfo";
const GetVideoInfoOptions = {
formatArgs: {
......@@ -17036,23 +17037,34 @@ var ImagePreview = /* @__PURE__ */ defineSystemComponent({
}
});
let state$2 = null;
let imagePreviewInstance;
const closePreviewImageView = () => {
state$2 = null;
nextTick(() => {
imagePreviewInstance == null ? void 0 : imagePreviewInstance.unmount();
imagePreviewInstance = null;
});
};
const previewImage = /* @__PURE__ */ defineAsyncApi(API_PREVIEW_IMAGE, (args, { resolve }) => {
if (!state$2) {
state$2 = reactive(args);
nextTick(() => {
const app = createRootApp(ImagePreview, state$2, () => {
state$2 = null;
nextTick(() => {
app.unmount();
});
});
app.mount(ensureRoot("u-a-p"));
imagePreviewInstance = createRootApp(ImagePreview, state$2, closePreviewImageView);
imagePreviewInstance.mount(ensureRoot("u-a-p"));
});
} else {
extend(state$2, args);
}
resolve();
}, PreviewImageProtocol, PreviewImageOptions);
const closePreviewImage = /* @__PURE__ */ defineAsyncApi(API_CLOSE_PREVIEW_IMAGE, (_, { resolve, reject }) => {
if (imagePreviewInstance) {
closePreviewImageView();
resolve();
} else {
reject();
}
});
let videoInput = null;
const chooseVideo = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_VIDEO, ({ sourceType, extension }, { resolve, reject }) => {
initI18nChooseFileMsgsOnce();
......@@ -19746,6 +19758,7 @@ var api = {
chooseFile,
chooseImage,
previewImage,
closePreviewImage,
chooseVideo,
request,
downloadFile,
......@@ -21863,4 +21876,4 @@ var index = /* @__PURE__ */ defineSystemComponent({
return openBlock(), createBlock("div", clazz, [loadingVNode]);
}
});
export { $emit, $off, $on, $once, index$8 as Ad, index$7 as AdContentPage, index$6 as AdDraw, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$y as Button, index$5 as Camera, index$w as Canvas, index$u as Checkbox, index$v as CheckboxGroup, index$a as CoverImage, index$b as CoverView, index$t as Editor, index$A as Form, index$s as Icon, index$r as Image, Input, index$z as Label, LayoutComponent, index$4 as LivePlayer, index$3 as LivePusher, Map$1 as Map, MovableArea, MovableView, index$q as Navigator, index$2 as PageComponent, index$9 as Picker, PickerView, PickerViewColumn, index$p as Progress, index$n as Radio, index$o as RadioGroup, ResizeSensor, index$m as RichText, ScrollView, index$l as Slider, Swiper, SwiperItem, index$k as Switch, index$j as Text, index$i as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$e as Video, index$h as View, index$d as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getClipboardData, getCurrentPages$1 as getCurrentPages, getEnterOptionsSync, getFileInfo, getImageInfo, getLaunchOptionsSync, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, interceptors, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offWindowResize, onAccelerometerChange, onAppLaunch, onCompassChange, onGyroscopeChange, onLocaleChange, onMemoryWarning, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$f as plugin, preloadPage, previewImage, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setClipboardData, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setPageMeta, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort };
export { $emit, $off, $on, $once, index$8 as Ad, index$7 as AdContentPage, index$6 as AdDraw, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$y as Button, index$5 as Camera, index$w as Canvas, index$u as Checkbox, index$v as CheckboxGroup, index$a as CoverImage, index$b as CoverView, index$t as Editor, index$A as Form, index$s as Icon, index$r as Image, Input, index$z as Label, LayoutComponent, index$4 as LivePlayer, index$3 as LivePusher, Map$1 as Map, MovableArea, MovableView, index$q as Navigator, index$2 as PageComponent, index$9 as Picker, PickerView, PickerViewColumn, index$p as Progress, index$n as Radio, index$o as RadioGroup, ResizeSensor, index$m as RichText, ScrollView, index$l as Slider, Swiper, SwiperItem, index$k as Switch, index$j as Text, index$i as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$e as Video, index$h as View, index$d as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closePreviewImage, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getClipboardData, getCurrentPages$1 as getCurrentPages, getEnterOptionsSync, getFileInfo, getImageInfo, getLaunchOptionsSync, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, interceptors, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offWindowResize, onAccelerometerChange, onAppLaunch, onCompassChange, onGyroscopeChange, onLocaleChange, onMemoryWarning, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$f as plugin, preloadPage, previewImage, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setClipboardData, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setPageMeta, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort };
......@@ -545,6 +545,16 @@ function handleEvent(event) {
return console.warn(type + ' not found');
}
this[methodName](event);
}
/**
* @param properties
*/
function fixProperties(properties) {
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined;
}
});
}
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
......@@ -931,6 +941,8 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
// 初始化 vue 实例
const mpInstance = this;
const isMiniProgramPage = isPage(mpInstance);
// 微信小程序 properties 为了解决警告问题,目前所有 type 都默认为 null,故导致部分 prop 默认值初始化不正确,故将 null 值 替换为 undefined
fixProperties(properties);
this.$vm = $createComponent({
type: vueOptions,
props: properties,
......
......@@ -30,6 +30,7 @@ export {
initWxsCallMethods,
findVmByVueId,
handleEvent,
fixProperties,
} from './runtime/util'
// protocols
......
......@@ -166,3 +166,13 @@ export function handleEvent(
}
;(this as any)[methodName](event)
}
/**
* @param properties
*/
export function fixProperties(properties: Record<string, any>) {
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined
}
})
}
......@@ -540,6 +540,16 @@ function handleEvent(event) {
return console.warn(type + ' not found');
}
this[methodName](event);
}
/**
* @param properties
*/
function fixProperties(properties) {
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined;
}
});
}
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
......@@ -858,6 +868,8 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
// 初始化 vue 实例
const mpInstance = this;
const isMiniProgramPage = isPage(mpInstance);
// 微信小程序 properties 为了解决警告问题,目前所有 type 都默认为 null,故导致部分 prop 默认值初始化不正确,故将 null 值 替换为 undefined
fixProperties(properties);
this.$vm = $createComponent({
type: vueOptions,
props: properties,
......
......@@ -513,6 +513,16 @@ function findVmByVueId(instance, vuePid) {
return parentVm;
}
}
}
/**
* @param properties
*/
function fixProperties(properties) {
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined;
}
});
}
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
......@@ -917,6 +927,13 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
mpInstance.route = mpInstance.__route__;
}
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
fixProperties(properties);
this.$vm = $createComponent({
type: vueOptions,
......@@ -941,20 +958,6 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
{
return { attached, detached };
}
}
function fixProperties(properties) {
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined;
}
});
}
const mocks = [
......
......@@ -510,6 +510,16 @@ function findVmByVueId(instance, vuePid) {
return parentVm;
}
}
}
/**
* @param properties
*/
function fixProperties(properties) {
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined;
}
});
}
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
......@@ -820,6 +830,8 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
// 初始化 vue 实例
const mpInstance = this;
const isMiniProgramPage = isPage(mpInstance);
// 微信小程序 properties 为了解决警告问题,目前所有 type 都默认为 null,故导致部分 prop 默认值初始化不正确,故将 null 值 替换为 undefined
fixProperties(properties);
this.$vm = $createComponent({
type: vueOptions,
props: properties,
......
......@@ -513,6 +513,16 @@ function findVmByVueId(instance, vuePid) {
return parentVm;
}
}
}
/**
* @param properties
*/
function fixProperties(properties) {
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined;
}
});
}
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
......@@ -917,6 +927,13 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
mpInstance.route = mpInstance.__route__;
}
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
fixProperties(properties);
this.$vm = $createComponent({
type: vueOptions,
......@@ -957,20 +974,6 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
},
detached,
};
}
function fixProperties(properties) {
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined;
}
});
}
const mocks = [
......
......@@ -5,6 +5,7 @@ import {
MPComponentInstance,
CreateComponentOptions,
CreateLifetimesOptions,
fixProperties,
} from '@dcloudio/uni-mp-core'
import {
......@@ -42,7 +43,13 @@ export function initLifetimes({
if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
mpInstance.route = mpInstance.__route__
}
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
fixProperties(properties)
this.$vm = $createComponent(
......@@ -98,18 +105,3 @@ export function initLifetimes({
detached,
}
}
function fixProperties(properties: Record<string, any>) {
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined
}
})
}
......@@ -34,8 +34,13 @@ export function buildOptions(): UserConfig['build'] {
// sourcemap: 'inline', // TODO
// target: ['chrome53'], // 由小程序自己启用 es6 编译
emptyOutDir: false, // 不清空输出目录,否则会影响自定义的一些文件输出,比如wxml
lib: {
// 必须使用 lib 模式,否则会生成 preload 等代码
fileName: 'app.js',
entry: resolveMainPathOnce(inputDir),
formats: ['cjs'],
},
rollupOptions: {
input: resolveMainPathOnce(inputDir),
output: {
entryFileNames: 'app.js',
format: 'cjs',
......
......@@ -2882,7 +2882,9 @@ const getPublicInstance = (i) => {
};
const publicPropertiesMap = extend(Object.create(null), {
$: i => i,
$el: i => i.vnode.el,
// fixed by xxxxxx vue-i18n 在 dev 模式,访问了 $el,故模拟一个假的
// $el: i => i.vnode.el,
$el: i => i.__$el || (i.__$el = {}),
$data: i => i.data,
$props: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.props) : i.props),
$attrs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.attrs) : i.attrs),
......@@ -4880,6 +4882,7 @@ var plugin = {
initApp(app);
// TODO 旧编译器使用了$createElement 导致告警,当切换到新编译器时,移除此类代码
app.config.globalProperties.$createElement = () => { };
app.config.globalProperties.$el = {};
const oldMount = app.mount;
app.mount = function mount(rootContainer) {
const instance = oldMount.call(app, rootContainer);
......@@ -5127,4 +5130,4 @@ function createApp(rootComponent, rootProps = null) {
}
const createSSRApp = createApp;
export { EffectScope, ReactiveEffect, c, callWithAsyncErrorHandling, callWithErrorHandling, computed, createApp, createSSRApp, createVNode$1 as createVNode, createVueApp, customRef, d, defineComponent, defineEmits, defineExpose, defineProps, e, effect, effectScope, f, getCurrentInstance, getCurrentScope, h, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, n, nextTick, o, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onUnmounted, onUpdated, patch, provide, proxyRefs, queuePostFlushCb, r, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, s, setupDevtoolsPlugin, shallowReactive, shallowReadonly, shallowRef, stop, t, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useSSRContext, useSlots, version, w, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId };
export { EffectScope, Fragment, ReactiveEffect, Text, c, callWithAsyncErrorHandling, callWithErrorHandling, computed, createApp, createSSRApp, createVNode$1 as createVNode, createVueApp, customRef, d, defineComponent, defineEmits, defineExpose, defineProps, e, effect, effectScope, f, getCurrentInstance, getCurrentScope, h, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, n, nextTick, o, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onUnmounted, onUpdated, patch, provide, proxyRefs, queuePostFlushCb, r, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, s, setupDevtoolsPlugin, shallowReactive, shallowReadonly, shallowRef, stop, t, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useSSRContext, useSlots, version, w, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId };
......@@ -2882,7 +2882,9 @@ const getPublicInstance = (i) => {
};
const publicPropertiesMap = extend(Object.create(null), {
$: i => i,
$el: i => i.vnode.el,
// fixed by xxxxxx vue-i18n 在 dev 模式,访问了 $el,故模拟一个假的
// $el: i => i.vnode.el,
$el: i => i.__$el || (i.__$el = {}),
$data: i => i.data,
$props: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.props) : i.props),
$attrs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.attrs) : i.attrs),
......@@ -4727,4 +4729,4 @@ function createVueApp(rootComponent, rootProps = null) {
function withModifiers() { }
function createVNode$1() { }
export { EffectScope, ReactiveEffect, callWithAsyncErrorHandling, callWithErrorHandling, computed, createVNode$1 as createVNode, createVueApp, customRef, defineComponent, defineEmits, defineExpose, defineProps, effect, effectScope, getCurrentInstance, getCurrentScope, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onUnmounted, onUpdated, patch, provide, proxyRefs, queuePostFlushCb, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, shallowReactive, shallowReadonly, shallowRef, stop, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useSSRContext, useSlots, version, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId };
export { EffectScope, Fragment, ReactiveEffect, Text, callWithAsyncErrorHandling, callWithErrorHandling, computed, createVNode$1 as createVNode, createVueApp, customRef, defineComponent, defineEmits, defineExpose, defineProps, effect, effectScope, getCurrentInstance, getCurrentScope, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onUnmounted, onUpdated, patch, provide, proxyRefs, queuePostFlushCb, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, shallowReactive, shallowReadonly, shallowRef, stop, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useSSRContext, useSlots, version, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId };
......@@ -8,6 +8,7 @@ export default {
// TODO 旧编译器使用了$createElement 导致告警,当切换到新编译器时,移除此类代码
app.config.globalProperties.$createElement = () => {}
app.config.globalProperties.$el = {}
const oldMount = app.mount
app.mount = function mount(rootContainer: any) {
......
......@@ -391,6 +391,16 @@ function findVmByVueId(instance, vuePid) {
return parentVm;
}
}
}
/**
* @param properties
*/
function fixProperties(properties) {
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined;
}
});
}
function createObserver(name) {
......@@ -697,6 +707,8 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
// 初始化 vue 实例
const mpInstance = this;
const isMiniProgramPage = isPage(mpInstance);
// 微信小程序 properties 为了解决警告问题,目前所有 type 都默认为 null,故导致部分 prop 默认值初始化不正确,故将 null 值 替换为 undefined
fixProperties(properties);
this.$vm = $createComponent({
type: vueOptions,
props: properties,
......
......@@ -5,6 +5,7 @@ import {
MPComponentInstance,
CreateComponentOptions,
CreateLifetimesOptions,
fixProperties,
} from '@dcloudio/uni-mp-core'
import {
......@@ -36,6 +37,9 @@ export function initLifetimes({
const mpInstance = this
const isMiniProgramPage = isPage(mpInstance)
// 微信小程序 properties 为了解决警告问题,目前所有 type 都默认为 null,故导致部分 prop 默认值初始化不正确,故将 null 值 替换为 undefined
fixProperties(properties)
this.$vm = $createComponent(
{
type: vueOptions,
......
......@@ -491,6 +491,16 @@ function initRefs(instance, mpInstance) {
return $refs;
},
});
}
/**
* @param properties
*/
function fixProperties(properties) {
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined;
}
});
}
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
......@@ -886,6 +896,13 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
mpInstance.route = mpInstance.__route__;
}
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
fixProperties(properties);
this.$vm = $createComponent({
type: vueOptions,
......@@ -910,20 +927,6 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
{
return { attached, detached };
}
}
function fixProperties(properties) {
// 字节跳动小程序 properties
// 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
// 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
// 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
// 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
// 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
// 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
Object.keys(properties).forEach((name) => {
if (properties[name] === null) {
properties[name] = undefined;
}
});
}
const instances = Object.create(null);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册