I've created an API with FastApi and this is the only thing it has stored in it: {"data":[-17,23,-11,-10,-7]}. And I've tested it and it returns the correct thing when I run it with Python. But why in this Vue.js website I'm creating it only returns [object Promise] when I'm using Axios to call it?
<script>
import ProductService from '../service/ProductService';
import axios from 'axios';
export default {
data() {
return {
products: null,
lineData: {
labels: ['january', 'second', 'third', 'fourth', 'fifth'],
datasets: [
{
label: 'Revenue',
data: [-0, 23, -11, -10, -7],
fill: false,
backgroundColor: '#2f4860',
borderColor: '#2f4860',
tension: 0.4
},
{
label: 'Profits',
data: [], # I want my API to put the list of datapoints here
fill: false,
backgroundColor: '#00bb7e',
borderColor: '#00bb7e',
tension: 0.4
}
]
},
items: [
{label: 'Add New', icon: 'pi pi-fw pi-plus'},
{label: 'Remove', icon: 'pi pi-fw pi-minus'}
]
}
},
productService: null,
created() {
this.productService = new ProductService();
},
mounted() {
this.productService.getProductsSmall().then(data => this.products = data);
axios #Here I am calling the API
.get('http://localhost:8000/')
.then(response => {(this.lineData.datasets[1].data = response.data)})
},
methods: {
formatCurrency(value) {
return value.toLocaleString('en-US', {style: 'currency', currency: 'USD'});
}
}
}
</script>
Edit:
Okay now I logged it. This is what I got:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8000/. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 200.
and
createError createError.js:16
handleError xhr.js:117
dispatchXhrRequest xhr.js:114
xhrAdapter xhr.js:15
dispatchRequest dispatchRequest.js:58
request Axios.js:108
method Axios.js:129
wrap bind.js:9
mounted Dashboard.vue:285
callWithErrorHandling runtime-core.esm-bundler.js:6992
callWithAsyncErrorHandling runtime-core.esm-bundler.js:7001
__weh runtime-core.esm-bundler.js:2270
flushPostFlushCbs runtime-core.esm-bundler.js:7193
flushJobs runtime-core.esm-bundler.js:7230```