-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added mixin and added lazy loading to interior hero
- Loading branch information
Showing
6 changed files
with
82 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
export default { | ||
props: { | ||
imageSource: { | ||
type: String, | ||
required: true | ||
}, | ||
loadingImage: { | ||
type: String, | ||
required: true | ||
}, | ||
errorImage: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
methods: { | ||
fetchImage () { | ||
this.asyncImage.onload = this.imageOnLoad | ||
this.asyncImage.onerror = this.imageOnError | ||
this.imageState = 'loading' | ||
this.asyncImage.src = this.imageSource | ||
}, | ||
imageOnLoad (success) { | ||
this.imageState = 'loaded' | ||
}, | ||
imageOnError (error) { | ||
this.imageState = 'error' | ||
console.error(error) | ||
} | ||
}, | ||
data: function () { | ||
return { | ||
imageState: 'loading', | ||
asyncImage: new Image() | ||
} | ||
}, | ||
mounted: function () { | ||
if (this.loadingImage) { | ||
this.$nextTick(() => { | ||
this.fetchImage() | ||
}) | ||
} | ||
}, | ||
computed: { | ||
computedImageSrc: function () { | ||
if (this.imageState === 'loading') { | ||
return this.loadingImage | ||
} | ||
if (this.imageState === 'error') { | ||
return this.errorImage | ||
} | ||
if (this.imageState === 'loaded') { | ||
return this.asyncImage.src | ||
} | ||
|
||
return '' | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters