受欢迎的博客标签

You can use setInterval().

Following is the minimally modified code for vueApp.js to add auto-refresh functionality (after every 10 seconds):

const url = "https://min-api.cryptocompare.com/data/pricemulti?fsyms=BTC,ETH&tsyms=USD,EUR";

const vm = new Vue(

{

el: '#app',

data: {

results: []

},

mounted()

{

this.upDate();

this.timer = setInterval(this.upDate, 10000)

},

methods:

{

upDate: function()

{

axios.get(url)

.then(response =>

{

this.results = response.data

})

},

cancelAutoUpdate: function()

{

clearInterval(this.timer)

},

beforeDestroy()

{

clearInterval(this.timer)

}

}

});.