title: How can I call a method every x seconds?
body: <p>I need to call the method getBitcoins() every second. </p>
  
  <blockquote>
    <p>Tried: I tried just taking it out the methods and putting it under the
    line <code>import Pickaxe from '../assets/pickaxe.png'</code> and then using
    setInterval to call it every second, but then I can't access the data
    variable btcPrice inside getBitcoins().</p>
  </blockquote>
  
  <p>So I need a way to call the getBitcoins() from the methods functions every second, just as it is in the code below.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;template&gt;
    &lt;div id="wrapper"&gt;
      &lt;div class="top"&gt;&lt;/div&gt;
      &lt;!-- Center --&gt;
      &lt;div class="center"&gt;
        &lt;img :src="Pickaxe" class="Pickaxe"&gt;
        &lt;span class="my-btc"&gt;{{ mybtc.toFixed(8) }}&lt;/span&gt;
        &lt;span id="btc"&gt;1 BTC = {{ btcPrice }}&lt;/span&gt;
        &lt;button class="Mine"&gt;Mine&lt;/button&gt;
        &lt;span class="hashes"&gt;{{btcMin}} btc/min&lt;/span&gt;
        &lt;button class="Upgrade"&gt;UPGRADE&lt;/button&gt;
        &lt;span class="upgradePrice"&gt;{{ upgradePrice }}btc&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/template&gt;
  
  &lt;script&gt;
    import bitcoin from '../assets/bitcoin.svg'
    import Pickaxe from '../assets/pickaxe.png'
  
    export default {
      name: 'landing-page',
      data() {
        return {
          bitcoin,
          Pickaxe,
     
          mybtc: 1,
          btcPrice: null,
          btcMin: 0,
  
          upgradePrice: 0
  
        }
      },
      methods: {
        getBitcoins() {
          var currentPrice = new XMLHttpRequest();
          currentPrice.open('GET', 'https://api.gdax.com/products/BTC-USD/book', true);
          currentPrice.onreadystatechange = function(){
            if(currentPrice.readyState == 4){
              let ticker = JSON.parse(currentPrice.responseText);
              let price = ticker.bids[0][0];
          document.getElementById('btc').innerHTML = "1 BTC = " + price + "$";
         };
        };
          currentPrice.send();
        }
      }
    }
  &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>