IMG SRC数据绑定返回403

时间:2018-10-11 15:43:34

标签: vue.js vuejs2 axios

我正在尝试使用Vue.js和axios创建漫画的在线阅读器应用程序。在下面的代码中,我试图从CDN加载正确的图像。

<template>
<div class="chapter">
    <div class="chapter-content">
        <img class="lazy" :src="'//cdn.mangaeden.com/mangasimg/'+ chapter[n][1]" :srcset="'//cdn.mangaeden.com/mangasimg/'+ chapter[n][1] ">
    </div>
    <div class="chapter-nav">
        <div class="btn">
            <button @click="n++" :disabled="n >= chapter[1].length - 1">Next</button>
        </div>
        <div class="btn">
            <button @click="n--" :disabled="n <= 0">Prev</button>
        </div>
    </div>
</div>
</template>
<script>
import { HTTP } from '../environment'

export default {
    name: "chapter",
    props: ['id'],

    data(){
        return {
            chapter: [],
            n:0,
        }
    },

    methods: {

        getChapter(id){
            var vm = this;
            HTTP.get('/chapter/'+ id)
                .then(function(response){
                    vm.chapter = response.data.images;
                    vm.lazyLoad();
                })
                .catch(function (error) {
                    console.log(error)
                });
        },
    },

    created(){
        this.getChapter(this.id);
    },

    watch:{
        '$route'(){
            this.getChapter(this.id);
        }
    }

}
</script>

在浏览器中打开我的应用程序时,这将返回403 Forbidden错误。困扰我的问题是,只有在浏览器的另一个选项卡中打开图像src时,图像才会加载。然后该应用程序就可以正常运行了。

0 个答案:

没有答案