createApp({
setup() {
let price = 0
onMounted() {
// axios
price = axios.response
}
return { price }
}
}).mount('#app')
HTML
<h6 id="app" >{{price}}</h6>
The current situation is that a value of 0 is continuously output. Looking at the order, it seems that the setup function returns before the onMounted function and has already done the rendering.
What should I do?
CodePudding user response:
You should use price = ref(0)
for reactivity.
https://vuejs.org/api/composition-api-setup.html#basic-usage