I have the problem that a variable which I create in created() cannot be used in the fetchData function under Methods. It is undefined there. I can’t reference This and I don’t know how to do that.
<script>
export default {
data () {
return {
p: ''
}
},
async created() {
try {
const res = await useFetch('XXX/api',{mode: 'no-cors'}).data.value;
//data from res...
let p = '[ '
//p transformation with data from res
this.p = p;
} catch (err) {
console.log(err);
}
},
mounted () {
this.fetchData()
},
methods: {
async fetchData () {
//other stuff
//I need the p variable here
//this.p = undefined
x = this.p
}
}
}
</script>
I think the solution is to pass the “this” or to use the “=>”. But unfortunately I don’t know how to do this.