I know this question has been asked multiple times already and the answers I have found and have followed them but without success.
Summary: I need to get the array from the classes.json
file and then set variable classes
from data()
to that json data
.
This is the classes.json file I need to load the array from.
[{
"School1": {
"classTag": ["F1", "E2G", "E2E", "E2A"]
}
},
{
"School2": {
"classTag": ["10BFTE", "11BFTE"]
}
}
]
These are the methods I've tried:
created() {
// Load json to classes
$.getJSON('../assets/classes.json', function(json) {
for (var key in json) {
if (json.hasOwnProperty(key)) {
var item = json[key];
this.classes.push({
classTag: item.classTag
});
}
}
});
}
created() {
$.getJSON('../assets/classes.json', function(data) {
this.classes = data;
}).error(function() {
console.log('error: json not loaded');
});
}
Both of the them and others give me this error: Vue Err Msg