now there is a string and a list to be updated with the results obtained in axios. When updating the list, there are several local values to be displayed first, and then the results obtained by axios are added to the back of the list. I have studied for most of the day and only found such a way to add the update function to the created hook. Ask the bosses if there are other better ways to update the data.
</script>
<script>
let vm = new Vue({
el: "-sharpapp",
data() {
return {
greeting: "",
items: []
}
},
computed: {
},
methods: {
update_greeting: function () {
axios.get("https://httpbin.org/ip")
.then(resp => {
this.greeting = "hello"
console.log("greeting updated")
})
.catch(err => console.error(err))
},
update_items: function () {
this.items = [1, 2, 3]
axios.get("https://httpbin.org/ip")
.then(resp => {
this.items.push(4)
console.log("items updated")
})
.catch(err => console.error(err))
},
},
created: function () {
this.update_greeting()
this.update_items()
}
})
</script>
</body>
</html>
I have also tried a comma method to put the initial value in data, and then update data, in the calculation properties so that although it can be updated, it can be updated at least twice, and it will end up in an endless loop. It seems that there is no good way to do this except the created hook. What do the bosses do in this situation?