I am new in JS (and vue too) and have problem witch fetch data. My target is - want to save all data from API and using them in functions.
Code:
<div>{{ dotToComma }} kg</div>
Vue:
export default {
data() {
return {
weight: null
};
},
created() {
this.api();
},
methods: {
//this is working correctly
async api() {
const api = await fetch("/reporting/patient/values");
const data = await api.json();
this.weight = Math.round(data.weight * 10) / 10
}
},
computed: {
//this.weight is still null
dotToComma() {
return this.weight.replace(".", ",");
}
}
};
Where is the problem? Thank you
UPDATE:
function replace in dotToComma is working only for strings, so you have to add toString() function:
return this.weight.toString().replace(".", ",");