我是vue的新手,我收到錯誤referenceError: items is not defined
。任何人都可以看到爲什麼發生這種情況,或者給我一些指點?Vue.js 2組件父項子項未定義
我認爲這與items
有關,不是先設置模板。
我的代碼:
<div id="root">
<task-list></task-list>
<template id="my-parent">
<table>
<thead>
<tr>
<th>Name</th>
<th>id</th>
</tr>
</thead>
<tbody>
<tr is="task" v-for="item in items" :item="item"></tr>
</tbody>
</table>
</template>
<template id="my-child">
<tr>
<td></td>
<td>{{ item.name }}</td>
<td>{{ item.id }}</td>
</tr>
</template>
</div>
<script>
Vue.component('task-list', {
template: '#my-parent',
data: function() {
return {
items: []
}
},
methods: {
getMyData: function(val) {
var _this = this;
$.ajax({
url: 'vuejson.php',
method: 'GET',
success: function (data) {
console.log(data);
_this.items = data;
},
error: function (error) {
alert(JSON.stringify(error));
}
})
}
},
mounted: function() {
this.getMyData("0");
}
});
Vue.component('task', {
template: '#my-child',
props: ['item'],
data: function() {
return {
item: {}
}
}
});
new Vue({
el: "#root",
});
</script>
我想你刪除了一個鏈接(url,image?)到你的代碼,因爲沒有代碼可見。不要修復鏈接,只需將代碼編寫爲純ASCII。 – Matthias
對不起,第一次使用stackoverflow –
更新了現在感謝 –