0👍
Firstly, you have to call API
within a Function like this:
<script>
export default {
data() {
return {
list: []
}
},
methods: {
callAPI() {
axios.get('/', then(function(res){
this.list = res.data.registerList;
}))
}
},
mounted(){
this.callAPI(); // if you need that List on load then you can use mounted() otherwise that function will call during event.
}
}
</script>
Here, inside then()
I think it’s better to use function()
. Because if you use function then it will indicate this Object. So, we can easily access all the Object Properties (Like: data(), methods() etc.).
Source:stackexchange.com