这是我的代码:
// Advert.vue
<template>
<div>
<ul class="list-group">
<li v-for="category in categories" @click="sendAdvert(category.id)" class="list-group-item display">
{{ category.name }}
</li>
</ul>
</div>
</template>
<script>
export default {
props: ['categories'],
data() {
return {
advert: [],
}
},
methods: {
sendAdvert(id) {
axios.get('/adverts/'+id)
.then(response => {
this.advert = response.data;
});
}
}
}
</script>
并且:
// AdvertController.php
public function show(Request $request, $advert)
{
return Category::find($advert);
}
// Category.php
class Category extends Model
{
protected $fillable = ['name', 'parent_id'];
}
-
这是我得到的输出:
这是预期的结果(我正在关注的教程输出):
有人知道为什么我没有得到预期的输出吗?