vue+已拦截跨源请求:同源策略禁止读取位于 http://192.168.43.168:8080/category/list 的远程资源。CORS 头缺少 'Access-Control-Allow

vue访问Java后台时候出现

@CrossOrigin 加一个这个注解就可以

    @RequestMapping("/list")
    @CrossOrigin
    public PagedResult getlist(@RequestParam(value = "pageNum",defaultValue = "1") int pageNum,@RequestParam(value = "pageSize",defaultValue = "10") int pageSize){

        PagedResult categoryPagedResulte=categoryService.getList(pageNum,pageSize);

        return categoryPagedResulte;
    }

 

 

vue配置axios 跨域

import axios from 'axios'


Vue.prototype.$ajax = axios

// Vue.prototype.$ajax = axios
Vue.config.productionTip = false
// axios 配置

axios.defaults.timeout = 5000;

// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';

axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8';

// axios.defaults.headers.post['Content-Type'] = 'json';

// axios.defaults.baseURL = 'http://localhost:8080/项目名/';

axios.defaults.baseURL = 'http://192.168.43.168:8080/';

 

你可能感兴趣的:(解决问题,前端)