vue实例没有挂载到html上,VueJS-将数据发送到Vue实例以用于挂载()
我對我的“項(xiàng)目”有幾個(gè)不同的清單,并使用相同的Vue實(shí)例來處理我從數(shù)據(jù)庫中獲得的這些清單。我遇到了一個(gè)問題,雖然我真的想在我的mounted()方法中使用項(xiàng)目的id和type清單來幫助我的控制器端點(diǎn)(我使用laravel,但在這里無關(guān))指向正確的數(shù)據(jù)庫行。VueJS-將數(shù)據(jù)發(fā)送到Vue實(shí)例以用于掛載()
因此,例如:
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()方法。
總結(jié)
以上是生活随笔為你收集整理的vue实例没有挂载到html上,VueJS-将数据发送到Vue实例以用于挂载()的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微信底栏新增“视频号”入口?腾讯张军否认
- 下一篇: 保险公司救援免费吗 保险带免费救援吗