Skip to content

Commit

Permalink
feat: add cors
Browse files Browse the repository at this point in the history
  • Loading branch information
huangxueliang committed Nov 11, 2019
1 parent cd8df3d commit e9c4a10
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/lazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default function (Vue) {
return Vue.nextTick(this.lazyLoadHandler)
}

let { src, loading, error } = this._valueFormatter(binding.value)
let { src, loading, error, cors } = this._valueFormatter(binding.value)

Vue.nextTick(() => {
src = getBestSelectionFromSrcset(el, this.options.scale) || src
Expand All @@ -137,6 +137,7 @@ export default function (Vue) {
loading,
error,
src,
cors,
elRenderer: this._elRenderer.bind(this),
options: this.options,
imageCache: this._imageCache
Expand Down
9 changes: 6 additions & 3 deletions src/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import {
// }

export default class ReactiveListener {
constructor ({ el, src, error, loading, bindType, $parent, options, elRenderer, imageCache }) {
constructor ({ el, src, error, loading, bindType, $parent, options, cors, elRenderer, imageCache }) {
this.el = el
this.src = src
this.error = error
this.loading = loading
this.bindType = bindType
this.attempt = 0
this.cors = cors

this.naturalHeight = 0
this.naturalWidth = 0
Expand Down Expand Up @@ -122,7 +123,8 @@ export default class ReactiveListener {
renderLoading (cb) {
this.state.loading = true
loadImageAsync({
src: this.loading
src: this.loading,
cors: this.cors
}, data => {
this.render('loading', false)
this.state.loading = false
Expand Down Expand Up @@ -160,7 +162,8 @@ export default class ReactiveListener {
this.record('loadStart')

loadImageAsync({
src: this.src
src: this.src,
cors: this.cors
}, data => {
this.naturalHeight = data.naturalHeight
this.naturalWidth = data.naturalWidth
Expand Down
3 changes: 3 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ const loadImageAsync = (item, resolve, reject) => {
}

image.src = item.src
if (item.cors) {
image.crossOrigin = item.cors
}

image.onload = function () {
resolve({
Expand Down

0 comments on commit e9c4a10

Please sign in to comment.