0👍
var VueCreator = function (id, endPoint) {
var myVue = new Vue({
el: id,
data: {
videos: []
},
ready: function() {
this.fetchVideos();
},
methods: {
fetchVideos: function() {
this.$http.get(endPoint, function(videos) {
this.videos = videos;
});
}
}
});
return myVue;
}
//pseudo code, assumes videoList is an object that has each unique list with an id and an endpoint
var lists = [];
forEach(videoList, function(obj) {
var tempList = new VueCreate(obj.id, obj.endPoint);
lists.push(tempList);
})
A general rule in js (and maybe all of coding) is if you need to do something more than once, write a function to do it.
- [Vuejs]-How to modify nested JSON data with Vue and Vue Resource
- [Vuejs]-Binding checkbox values if present in another array
Source:stackexchange.com