码迷,mamicode.com
首页 > 其他好文 > 详细

路飞-后台处理跨域问题

时间:2019-11-12 20:09:13      阅读:58      评论:0      收藏:0      [点我收藏+]

标签:font   中间件   splay   class   com   axios   headers   项目配置   led   

分离的前后台交互

后台处理跨域

安装插件
"""
>: pip install django-cors-headers

插件参考地址:https://github.com/ottoyiu/django-cors-headers/
"""
项目配置:dev.py
# 注册app
INSTALLED_APPS = [
    ...
    'corsheaders'
]

# 添加中间件
MIDDLEWARE = [
    ...
    'corsheaders.middleware.CorsMiddleware'
]

# 允许跨域源
CORS_ORIGIN_ALLOW_ALL = True

前台请求Banner数据

修订Banner.vue
<template>
    <el-carousel height="520px" :interval="3000" arrow="always">
        <!-- 渲染后台数据 -->
        <el-carousel-item v-for="banner in banner_list" :key="banner.name">
            <a :href="banner.link">
                <img :src="banner.image" alt="" :title="banner.note">
            </a>
        </el-carousel-item>

    </el-carousel>
</template>
<script>
    export default {
        name: "Banner",
        data() {
            return {
                banner_list: []
            }
        },
        created() {
            // 请求后台数据
            this.$axios({
                url: this.$settings.base_url + '/home/banners/',
                method: 'get',
            }).then(response => {
                // window.console.log(response.data);
                this.banner_list = response.data;
            }).catch(errors => {
                window.console.log(errors)
            })
        }
    }
</script>

<style scoped>
    .el-carousel__item h3 {
        color: #475669;
        font-size: 18px;
        opacity: 0.75;
        line-height: 300px;
        margin: 0;
    }

    .el-carousel__item:nth-child(2n) {
        background-color: #99a9bf;
    }

    .el-carousel__item:nth-child(2n+1) {
        background-color: #d3dce6;
    }
    .el-carousel__item img {
        text-align: center;
        height: 520px;
        margin: 0 auto;
        display: block;
    }
</style>

路飞-后台处理跨域问题

标签:font   中间件   splay   class   com   axios   headers   项目配置   led   

原文地址:https://www.cnblogs.com/DcentMan/p/11844543.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!