I have defined a async function in methods and when trying to call the same function in mounted.. it is giving the error – Uncaught TypeError: this.submitData is not a function.
Please help me out how to call async function in mounted() in vue js. Below is my code –
<script>
import axios from 'axios';
export default{
props:{
categories: {
default: []
},
},
data(){
return {
formData:{
category: [],
price: '',
},
}
},
methods: {
async submitData(){
try{
const response = await axios.post('/api/category', this.formData)
console.log(response);
}
catch(error){
console.log(error)
}
},
},
mounted() {
this.submitData()
.then((res)=>{
console.log(res);
})
.catch((err)=>{
console.log(err);
});
}
}
</script>