我对我的“项目”有几个不同的清单,并使用相同的Vue实例来处理我从数据库中获得的这些清单。我遇到了一个问题,虽然我真的想在我的mounted()方法中使用项目的id和type清单来帮助我的控制器端点(我使用laravel,但在这里无关)指向正确的数据库行。VueJS-将数据发送到Vue实例以用于挂载()
因此,例如:
HTML
JS
new Vue({
el: '.vue-checklist',
data: {
items: [],
// is there a way to trap those data attrs here?
},
mounted : function(){
// I need to a way to access the project and type data attrs.
this.fetchChecklist(this.project, this.type); //
},
methods: {
fetchChecklist : function(project, type){
this.$http.get('{ api/path }', { project: project, type: type}).then(function(response){
this.items = response.data;
})
}
});
再次,有没有办法让data-project和data-type附着在HTML中使用,在mounted()方法。