Vuejs receives image from a remote source

I use the following code to detect a button click and get an image from unsplash that has random mode.

The problem is that it works once to get random. But the second time this does not change.

He does not request it again, he simply does not change it, because the same URL I think.

var vue = new Vue({
  el: '#app',
  data: {
    styleObject: {
        background: 'url(https://unsplash.it/1920/1080)'
    }
  },
  methods: {
    getImage: function() {
        vue.styleObject.background = 'url(https://unsplash.it/1920/1080?random)'
    }
  }
})

I tried to erase a variable

getImage: function() {
    vue.styleObject.background = '';
    vue.styleObject.background = 'url(https://unsplash.it/1920/1080?random)'
}

But still no success, any ideas? thank you

+4
source share
1 answer

. , , . :

 methods: {
    getImage: function() {
        var max = 90000;
        var min = 10000;
        var slug = Math.random() * (max - min) + min;
        vue.styleObject.background = 'url(https://unsplash.it/1920/1080?random&s=' + slug +')';
    }
  }

,

+6

Source: https://habr.com/ru/post/1627422/


All Articles