I am trying to transfer the result of a response to a characters object, but it throws an error:
Cannot read property 'characters' of undefined
<script>
const axios = require("axios");
export default {
data: () => ({
characters:[],
}),
created() {
axios
.get("https://rickandmortyapi.com/api/character")
.then(function(response) {
const resp = response.data.results;
this.characters.push(resp);
})
.catch(function(error) {
// handle error
console.log(error);
});
},
};
</script>