Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
5a0f4000
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
725
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5a0f4000
编写于
3月 11, 2019
作者:
X
xiaoyucoding
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 修复部分情况下 base64 的图片无法加载的问题
上级
4d725cbf
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
42 addition
and
38 deletion
+42
-38
src/core/view/components/image/index.vue
src/core/view/components/image/index.vue
+42
-38
未找到文件。
src/core/view/components/image/index.vue
浏览文件 @
5a0f4000
<
template
>
<
template
>
<uni-image
v-on=
"$listeners"
>
<uni-image
v-on=
"$listeners"
>
<div
:style=
"modeStyle
"
/>
<div
ref=
"content
"
/>
<img
:src=
"realImagePath"
>
<img
:src=
"realImagePath"
>
<v-uni-resize-sensor
<v-uni-resize-sensor
v-if=
"mode === 'widthFix'"
v-if=
"mode === 'widthFix'"
ref=
"sensor"
ref=
"sensor"
@
resize=
"_resize"
/>
@
resize=
"_resize"
/>
...
@@ -40,8 +40,42 @@ export default {
...
@@ -40,8 +40,42 @@ export default {
},
},
realImagePath
()
{
realImagePath
()
{
return
this
.
$getRealPath
(
this
.
src
)
return
this
.
$getRealPath
(
this
.
src
)
}
},
watch
:
{
src
(
newValue
,
oldValue
)
{
this
.
_loadImage
()
},
},
modeStyle
()
{
mode
(
newValue
,
oldValue
)
{
if
(
oldValue
===
'
widthFix
'
)
{
this
.
$el
.
style
.
height
=
this
.
availHeight
this
.
sizeFixed
=
false
}
if
(
newValue
===
'
widthFix
'
&&
this
.
ratio
)
{
this
.
_fixSize
()
}
this
.
_computeModeStyle
()
}
},
mounted
()
{
this
.
_computeModeStyle
()
this
.
availHeight
=
this
.
$el
.
style
.
height
||
''
this
.
_loadImage
()
},
methods
:
{
_resize
()
{
if
(
this
.
mode
===
'
widthFix
'
&&
!
this
.
sizeFixed
)
{
this
.
_fixSize
()
}
},
_fixSize
()
{
const
elWidth
=
this
.
_getWidth
()
if
(
elWidth
)
{
this
.
$el
.
style
.
height
=
elWidth
/
this
.
ratio
+
'
px
'
this
.
sizeFixed
=
true
}
},
_computeModeStyle
()
{
let
size
=
'
auto
'
let
size
=
'
auto
'
let
position
=
''
let
position
=
''
let
repeat
=
'
no-repeat
'
let
repeat
=
'
no-repeat
'
...
@@ -56,7 +90,7 @@ export default {
...
@@ -56,7 +90,7 @@ export default {
position
=
'
center center
'
position
=
'
center center
'
break
break
case
'
widthFix
'
:
case
'
widthFix
'
:
size
=
'
100% 100%
;
'
size
=
'
100% 100%
'
break
break
case
'
top
'
:
case
'
top
'
:
position
=
'
center top
'
position
=
'
center top
'
...
@@ -90,40 +124,10 @@ export default {
...
@@ -90,40 +124,10 @@ export default {
position
=
'
0% 0%
'
position
=
'
0% 0%
'
break
break
}
}
this
.
$refs
.
content
.
style
.
backgroundImage
=
`url(
${
this
.
realImagePath
}
)`
return
`background-image: url("
${
this
.
$getRealPath
(
this
.
src
)}
"); background-size:
${
size
}
;background-position:
${
position
}
;background-repeat:
${
repeat
}
;`
this
.
$refs
.
content
.
style
.
backgroundPosition
=
position
}
this
.
$refs
.
content
.
style
.
backgroundSize
=
size
},
this
.
$refs
.
content
.
style
.
backgroundRepeat
=
repeat
watch
:
{
src
(
newValue
,
oldValue
)
{
this
.
_loadImage
()
},
mode
(
newValue
,
oldValue
)
{
if
(
oldValue
===
'
widthFix
'
)
{
this
.
$el
.
style
.
height
=
this
.
availHeight
this
.
sizeFixed
=
false
}
if
(
newValue
===
'
widthFix
'
&&
this
.
ratio
)
{
this
.
_fixSize
()
}
}
},
mounted
()
{
this
.
availHeight
=
this
.
$el
.
style
.
height
||
''
this
.
_loadImage
()
},
methods
:
{
_resize
()
{
if
(
this
.
mode
===
'
widthFix
'
&&
!
this
.
sizeFixed
)
{
this
.
_fixSize
()
}
},
_fixSize
()
{
const
elWidth
=
this
.
_getWidth
()
if
(
elWidth
)
{
this
.
$el
.
style
.
height
=
elWidth
/
this
.
ratio
+
'
px
'
this
.
sizeFixed
=
true
}
},
},
_loadImage
()
{
_loadImage
()
{
const
_self
=
this
const
_self
=
this
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录