title: Cancelling previous API requests with Axios
body: <p>I am trying to follow Axios documentation to cancel repeated requests to an URL but while I get no errors the requests aren't being cancelled. I still can do as many as I want through the following method.</p>
  
  <pre><code>import axios from 'axios'
  
  getData({commit,state,dispatch}, id){
        const CancelToken = axios.CancelToken;
        const source = CancelToken.source();
        axios
        .get("http://15.100.100.100:9999/getData/" + id,{
          cancelToken: source.token
        }).catch(function (thrown) {
          if (axios.isCancel(thrown)) {
            console.log('Request canceled', thrown.message);
          } else {
            console.log("cancel error")
          }
        })
      },
  </code></pre>
  
  <p>I followed Axios documentation found here <a href="https://github.com/axios/axios#cancellation" rel="nofollow noreferrer">https://github.com/axios/axios#cancellation</a></p>
  
  <p>EDIT: Kaushik Makwana's answer was correct but in my case, instead of saving in a regular variable, i saved it in a state since my axios calls are made in my store.js file.</p>