[Vuejs]-Vue not returning data when consuming API

1๐Ÿ‘

I suspect the issue could be with your API.

Test the API on Postman / Postwoman / Insomnia to see the response.
If the API returns data on the API testing tool, it should function well when consumed on axios.

See below example:

var app = new Vue({
       el: '#app',

       data: {
        response: '',
       },     
 
       methods:{
        runApi:function(){
            axios.get('https://jsonplaceholder.typicode.com/todos/1').then(response=>{
                this.response = response.data;
                console.log(this.response);
                
            }).catch(function(error){
                console.log('error : ',error);
            })  
        }
       },

       mounted:function(){
           this.runApi();        
        }
    })
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>


<div id="app">
<p>
{{ response }}
</p>
</div>
๐Ÿ‘คmutiemule

Leave a comment