I'm new to Vue and can't figure the following out. I have an app which connects to a JSON Api via a usePage()
usePage() let's me use "page" as an object which I can use and access inside the tag.
Like:
<p>This product costs {{page.price}} Euros and is {{page.width}} wide and {{page.colour}}</p>
However, can I access this "page" object also in the data() or methods: ?
Like:
export default {
components: {
…
},
// Vue 3 setup
setup () {
return {
page: usePage(),
}
},
data: function() {
return {
product: {
price: this.page.price,
width: this.page.width,
colour: this.page.colour
}
};
}
}
It seems to return undefined. Is it not possible in Vue to access the same objects outside the <template> tag than inside the <template> tag?
Thanks for any tips!