嗯,我能够正确显示图像,但它仍然无缘无故地在控制台中给出 JavaScript 错误。这是我的代码:
获取类别:
fetchCategory: function(){
this.$http.get('get_category').then(function(response){
this.$set('categories',response.json());
});
}
这是显示类别的表格:
<table class="table table-bordered table-responsive table-striped example1">
<thead>
<tr>
<th>ID</th>
<th>Category Name</th>
<th>Icon</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr v-for="category in categories">
<td>@{{ category.id }}</td>
<td>@{{ category.name }}</td>
<td><img src="{{url('/')}}/@{{ category.icon }}" width="150px"></td>
<td>Edit | Delete</td>
</tr>
</tbody>
</table>
它可以正确显示图像,但是 javascript 控制台仍然显示 2 404 错误,指示图像的 url 获取http://localhost/project/%7B%7B%20category.icon%20%7D%7D 404(未找到)
我应该忽略这个错误吗? 或者还有其他方法可以在图像路径中包含基本网址吗?
最佳答案
您应该绑定(bind)src
属性:
<img :src="'{{ url('/') }}/' + category.icon" width="150px">
关于javascript - 在 Vue JS 中显示表格内的图像以及基本 url (Laravel 5.2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38280468/