Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦里逆天
uni-app
提交
b64ad52c
U
uni-app
项目概览
梦里逆天
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
22
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b64ad52c
编写于
3月 11, 2019
作者:
X
xiaoyucoding
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 修复 src 变化时未同步更新 url 的问题
上级
5a0f4000
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
41 addition
and
41 deletion
+41
-41
src/core/view/components/image/index.vue
src/core/view/components/image/index.vue
+41
-41
未找到文件。
src/core/view/components/image/index.vue
浏览文件 @
b64ad52c
<
template
>
<
template
>
<uni-image
v-on=
"$listeners"
>
<uni-image
v-on=
"$listeners"
>
<div
ref=
"content"
/>
<div
ref=
"content"
:style=
"modeStyle"
/>
<img
:src=
"realImagePath"
>
<img
:src=
"realImagePath"
>
<v-uni-resize-sensor
<v-uni-resize-sensor
v-if=
"mode === 'widthFix'"
v-if=
"mode === 'widthFix'"
...
@@ -40,42 +42,8 @@ export default {
...
@@ -40,42 +42,8 @@ export default {
},
},
realImagePath
()
{
realImagePath
()
{
return
this
.
$getRealPath
(
this
.
src
)
return
this
.
$getRealPath
(
this
.
src
)
}
},
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
()
}
this
.
_computeModeStyle
()
}
},
mounted
()
{
this
.
_computeModeStyle
()
this
.
availHeight
=
this
.
$el
.
style
.
height
||
''
this
.
_loadImage
()
},
methods
:
{
_resize
()
{
if
(
this
.
mode
===
'
widthFix
'
&&
!
this
.
sizeFixed
)
{
this
.
_fixSize
()
}
},
},
_fixSize
()
{
modeStyle
()
{
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
'
...
@@ -124,12 +92,44 @@ export default {
...
@@ -124,12 +92,44 @@ export default {
position
=
'
0% 0%
'
position
=
'
0% 0%
'
break
break
}
}
this
.
$refs
.
content
.
style
.
backgroundImage
=
`url(
${
this
.
realImagePath
}
)`
this
.
$refs
.
content
.
style
.
backgroundPosition
=
position
return
`background-position:
${
position
}
;background-size:
${
size
}
;background-repeat:
${
repeat
}
;`
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
()
{
this
.
$refs
.
content
.
style
.
backgroundImage
=
`url(
${
this
.
realImagePath
}
)`
const
_self
=
this
const
_self
=
this
const
img
=
new
Image
()
const
img
=
new
Image
()
img
.
onload
=
function
(
$event
)
{
img
.
onload
=
function
(
$event
)
{
...
@@ -150,7 +150,7 @@ export default {
...
@@ -150,7 +150,7 @@ export default {
errMsg
:
`GET
${
_self
.
src
}
404 (Not Found)`
errMsg
:
`GET
${
_self
.
src
}
404 (Not Found)`
})
})
}
}
img
.
src
=
this
.
$getRealPath
(
this
.
src
)
img
.
src
=
this
.
realImagePath
},
},
_getWidth
()
{
_getWidth
()
{
const
computedStyle
=
window
.
getComputedStyle
(
this
.
$el
)
const
computedStyle
=
window
.
getComputedStyle
(
this
.
$el
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录