提交 0fb61a2e 编写于 作者: Q qiang

fix: image load

上级 c694bc4c
...@@ -106,7 +106,7 @@ function useImageState(rootRef: Ref<HTMLElement | null>, props: ImageProps) { ...@@ -106,7 +106,7 @@ function useImageState(rootRef: Ref<HTMLElement | null>, props: ImageProps) {
}) })
const state = reactive({ const state = reactive({
rootEl: rootRef, rootEl: rootRef,
src: computed(() => getRealPath(props.src)), src: computed(() => (props.src ? getRealPath(props.src) : '')),
origWidth: 0, origWidth: 0,
origHeight: 0, origHeight: 0,
origStyle: { width: '', height: '' }, origStyle: { width: '', height: '' },
...@@ -138,7 +138,11 @@ function useImageLoader( ...@@ -138,7 +138,11 @@ function useImageLoader(
const loadImage = (src: string) => { const loadImage = (src: string) => {
if (!src) { if (!src) {
resetImage() resetImage()
resetSize() state.origWidth = 0
state.origHeight = 0
state.imgSrc = ''
// 与微信小程序保持一致,保留之前样式
// resetSize()
return return
} }
if (!img) { if (!img) {
...@@ -215,6 +219,9 @@ function useImageSize( ...@@ -215,6 +219,9 @@ function useImageSize(
rootEl.style[names[1] as 'height' | 'width'] = rootEl.style[names[1] as 'height' | 'width'] =
fixNumber(value / ratio) + 'px' fixNumber(value / ratio) + 'px'
} }
if (__PLATFORM__ === 'app') {
window.dispatchEvent(new CustomEvent('updateview'))
}
} }
const resetSize = () => { const resetSize = () => {
const { style } = rootRef.value! const { style } = rootRef.value!
......
...@@ -5908,7 +5908,7 @@ function useImageState(rootRef, props2) { ...@@ -5908,7 +5908,7 @@ function useImageState(rootRef, props2) {
}); });
const state = reactive({ const state = reactive({
rootEl: rootRef, rootEl: rootRef,
src: computed(() => getRealPath(props2.src)), src: computed(() => props2.src ? getRealPath(props2.src) : ""),
origWidth: 0, origWidth: 0,
origHeight: 0, origHeight: 0,
origStyle: { origStyle: {
...@@ -5935,7 +5935,9 @@ function useImageLoader(state, { ...@@ -5935,7 +5935,9 @@ function useImageLoader(state, {
const loadImage = (src) => { const loadImage = (src) => {
if (!src) { if (!src) {
resetImage(); resetImage();
resetSize(); state.origWidth = 0;
state.origHeight = 0;
state.imgSrc = "";
return; return;
} }
if (!img) { if (!img) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册