2018-08-23 05:00:53 +01:00
|
|
|
<div class="lazy-image" style={computedStyle} >
|
2018-09-01 00:35:26 +01:00
|
|
|
<img
|
|
|
|
class={className}
|
|
|
|
aria-hidden={ariaHidden}
|
|
|
|
{alt}
|
|
|
|
{title}
|
|
|
|
{width}
|
|
|
|
{height}
|
|
|
|
src={displaySrc}
|
|
|
|
ref:node
|
|
|
|
/>
|
2018-03-14 06:07:30 +00:00
|
|
|
</div>
|
|
|
|
<style>
|
|
|
|
.lazy-image {
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
2018-03-14 14:24:16 +00:00
|
|
|
import { mark, stop } from '../_utils/marks'
|
2018-08-23 05:00:53 +01:00
|
|
|
import { decodeImage } from '../_utils/decodeImage'
|
2018-03-14 14:24:16 +00:00
|
|
|
|
2018-03-14 06:07:30 +00:00
|
|
|
export default {
|
2018-08-23 05:00:53 +01:00
|
|
|
async oncreate () {
|
2018-03-14 14:24:16 +00:00
|
|
|
mark('LazyImage oncreate()')
|
2018-08-23 05:00:53 +01:00
|
|
|
try {
|
2018-09-01 00:35:26 +01:00
|
|
|
await decodeImage(this.refs.node)
|
2018-08-23 05:00:53 +01:00
|
|
|
} catch (e) {
|
2018-09-01 00:35:26 +01:00
|
|
|
this.set({ error: true })
|
2018-03-14 14:24:16 +00:00
|
|
|
}
|
|
|
|
stop('LazyImage oncreate()')
|
2018-04-30 06:13:41 +01:00
|
|
|
},
|
|
|
|
data: () => ({
|
2018-09-01 00:35:26 +01:00
|
|
|
error: false,
|
2018-08-23 05:00:53 +01:00
|
|
|
fallback: void 0,
|
|
|
|
background: '',
|
|
|
|
width: void 0,
|
|
|
|
height: void 0,
|
|
|
|
className: '',
|
|
|
|
ariaHidden: '',
|
|
|
|
alt: '',
|
|
|
|
title: ''
|
|
|
|
}),
|
|
|
|
computed: {
|
2018-08-30 05:42:57 +01:00
|
|
|
computedStyle: ({ width, height, background }) => {
|
2018-08-23 05:00:53 +01:00
|
|
|
return [
|
|
|
|
width && `width: ${width}px;`,
|
|
|
|
height && `height: ${height}px;`,
|
|
|
|
background && `background: ${background};`
|
|
|
|
].filter(Boolean).join('')
|
2018-09-01 00:35:26 +01:00
|
|
|
},
|
|
|
|
displaySrc: ({ error, src, fallback }) => ((error && fallback) || src)
|
2018-08-23 05:00:53 +01:00
|
|
|
}
|
2018-03-14 06:07:30 +00:00
|
|
|
}
|
|
|
|
</script>
|