Sorry to post it, but I tried all solutions I found on the web. This seems to be a common problem but I just can't make it work. After a full day on it I give up. It must be a silly point, any vue.js guru will find the point in seconds. Any help will be appreciated.
The point : I receive some JSON and try to update my page with the received values, but the fields are null. jsonSettings.length
is always 0.
I think I understand why: it's surely because the 'pointer' on the arrays doesn't change so vue.js doesn't detect the change of the content, or something similar, but I just can't make it work and it's driving me CRAZY.
My HTML :
<!DOCTYPE html>
<html>
<head>
<title>List</title>
<script src="/js/vue.min.js"></script>
<script src="/js/axios.js"></script>
</head>
<body>
<div id="app">
Message : {{ message }} <BR>
Length : {{ jsonSettings.length }} <BR>
Typeof : {{ jsonSettings.typeof }} <BR>
<button v-on:click="getData()">Load data</button>
<button v-on:click="printData()">Print data</button>
</div>
</body>
<script src="/javascripts/axios.js"></script>
</html>
My JavaScript:
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!',
// jsonSettings: [],
},
methods: {
jsonSettings : function() {
return (
[
{ id: 0, resume: 'test 0'},
{ id: 1, resume: 'test 1'},
{ id: 2, resume: 'test 2'}
]
)
},
getData : function () {
axios.get('/axios/LoadAxiosData')
.then(function (response) {
this.jsonSettings = response.data;
this.message = "getData - I get objects : " + jsonSettings.length + " lines ";
this.$set('jsonSettings', response.data);
this.message = "getData - OK";
})
.catch(function (error) {
this.message = "getData - I get null";
});
},
printData: function () {
this.message = "printData - jsonSettings.length = [" + jsonSettings.length + "]";
jsonSettings.map((item, i) => console.log('Index:', i, 'Id:', item.resume));
}
}
})
Sorry again, but I just can't make it work and I'm stuck in the middle of the river because of this silly point :-(