javascript - 在 Vue JS 中显示表格内的图像以及基本 url (Laravel 5.2)

标签 javascript laravel laravel-5 vue.js vue-resource

嗯,我能够正确显示图像,但它仍然无缘无故地在控制台中给出 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/

相关文章:

php - Laravel 预加载约束问题

mysql - 如何在 Laravel 中获取相似的产品标签?

javascript - 如何替换字符串中的单词并忽略字符串中的数字

javascript - Canvas JS 图表不适用于大数据和小数据

javascript - 从方法返回的 Promise 未定义

laravel - checkout Laravel中的新分支后出现错误

laravel-5 - 授权尝试在 Laravel 5.4 中失败

javascript,获取数组中给定值的索引

Laravel 单元测试 - 运行所有测试

php - 使用不同的 where 子句对同一关系进行多个联接/存在的查询