vue访问Java后台时候出现

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

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

        PagedResult<Category> 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/';

 

Logo

前往低代码交流专区

更多推荐