ThinkPHP3 解决前后端分离项目跨域问题

    /*
    **  @author water
    **  @admin 跨域问题 
    **  @2018-10-10
    **  
    */

    public function _initialize(){
        $this->cross();
}

    public function cross(){
        header('Content-Type:application/json; charset=utf-8');
        header('Access-Control-Allow-Origin:前端域名地址'); 
        //header('Access-Control-Max-Age:86400'); 
        header('Access-Control-Allow-Methods:OPTIONS,POST,PUT,DELETE');
}

你可能感兴趣的:(前后端分离)