You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
By clicking “Sign up for GitHub”, you agree to our
terms of service
and
privacy statement
. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
createError.js:16 Uncaught (in promise) Error: Network Error at createError (createError.js:16) at XMLHttpRequest.handleError (xhr.js:69)
#2755
createError.js:16 Uncaught (in promise) Error: Network Error at createError (createError.js:16) at XMLHttpRequest.handleError (xhr.js:69)
ggmo
opened this issue
Feb 17, 2020
· 12 comments
Hello, when i use axios get somedata from api , ERROR occurs and i cannot fix it , plz help .
createError.js:16 Uncaught (in promise) Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:69)
with chrome debug can get data from api with crud method, but with axios in vue caught error;
import axios from 'axios'
import router from '@/router/routers'
import { Notification, MessageBox } from 'element-ui'
import store from '../store'
import { getToken } from '@/utils/auth'
import Config from '@/settings'
// 创建axios实例
const service = axios.create({
baseURL: process.env.NODE_ENV === 'production' ? process.env.VUE_APP_BASE_API : '/', // api 的 base_url
timeout: Config.timeout // 请求超时时间
// request拦截器
service.interceptors.request.use(
config => {
if (getToken()) {
config.headers['Authorization'] = getToken() // 让每个请求携带自定义token
// 数据交互走JSON
config.headers['Content-Type'] = 'application/json'
return config
error => {
// Do something with request error
console.log(error) // for debug
Promise.reject(error)
// response 拦截器
service.interceptors.response.use(
response => {
const code = response.status
if (code < 200 || code > 300) {
Notification.error({
title: response.message
return Promise.reject('error')
} else {
return response.data
error => {
let code = 0
try {
code = error.response.data.status
} catch (e) {
if (error.toString().indexOf('Error: timeout') !== -1) {
Notification.error({
title: '网络请求超时',
duration: 5000
return Promise.reject(error)
if (code) {
if (code === 401) {
MessageBox.confirm(
'登录状态已过期,您可以继续留在该页面,或者重新登录',
'系统提示',
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning'
).then(() => {
store.dispatch('LogOut').then(() => {
location.reload() // 为了重新实例化vue-router对象 避免bug
} else if (code === 403) {
router.push({ path: '/401' })
} else {
const errorMsg = error.response.data.message
if (errorMsg !== undefined) {
Notification.error({
title: errorMsg,
duration: 5000
} else {
Notification.error({
title: '接口请求失败',
duration: 5000
return Promise.reject(error)
export default service
my api defined with axios(mojo):
import request from '@/utils/mojo'
export function add(data) {
return request({
url: '
http://192.168.100.100:8080/devices
',
method: 'post',
export function del(ids) {
return request({
url: '
http://192.168.100.100:8080/devices
',
method: 'delete',
data: ids
export function edit(data) {
return request({
url: '
http://192.168.100.100:8080/devices
',
method: 'put',
export default { add, edit, del }
and the request is not sending to server, chrome debug info :
Request URL:
http://127.0.0.1:8002/devices?page=0&size=10&sort=id%2Cdesc
Referrer Policy: no-referrer-when-downgrade
there have no method
but with server side it work fine
[2020-02-17 21:15:17.44329] [2492] [info] Creating Routes for resource 'Device' (controller => Device)
[2020-02-17 21:15:17.44358] [2492] [debug] GET /devices (api_get)
[2020-02-17 21:15:17.44372] [2492] [debug] POST /devices (api_create)
[2020-02-17 21:15:17.44385] [2492] [debug] DELETE /devices/ (api_delete)
[2020-02-17 21:15:17.44401] [2492] [debug] PUT /devices/ (api_update)
[2020-02-17 21:15:17.44420] [2492] [debug] GET /devices/download (api_download)
[2020-02-17 21:15:17.44449] [2492] [info] Creating Routes for resource 'Firewall' (controller => Firewall)
[2020-02-17 21:15:17.44463] [2492] [debug] GET /firewalls (api_get)
[2020-02-17 21:15:17.44476] [2492] [debug] POST /firewalls (api_create)
[2020-02-17 21:15:17.44487] [2492] [debug] DELETE /firewalls/ (api_delete)
[2020-02-17 21:15:17.44495] [2492] [debug] PUT /firewalls/ (api_update)
[2020-02-17 21:15:17.44512] [2492] [debug] GET /firewalls/download (api_download)
[2020-02-17 21:15:17.44751] [2492] [info] Listening at "
http://0.0.0.0:8080
"
Server available at
http://0.0.0.0:8080
[2020-02-17 21:15:21.82063] [2492] [debug] [b3ad801b] GET "/devices"
[2020-02-17 21:15:21.82514] [2492] [debug] [b3ad801b] Routing to controller "FirewallManager::Controller::Device" and action "get"
$VAR1 = bless( {
'headers' => {
'access-control-allow-origin' => [
'server' => [
'PERL'
}, 'Mojo::Headers' );
[2020-02-17 21:15:21.82694] [2492] [debug] [b3ad801b] 200 OK (0.006289s, 159.008/s)
reques-header info:
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36
Accept:
/
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: username=admin; rememberMe=true; password=0PVUYoRt1BpfnQKrahkn6+s8Z7FZXgnVU+tyoq7lze9v3JUcQkha8p6MMubzp4nt3DGre6mFY5GH7potSol+7Q==;TOEKN=Bearer%20eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJkZXB0OmVkaXQsdXNlcjpsaXN0LHN0b3JhZ2U6YWRkLGRlcHQ6YWRkLHN0b3JhZ2U6ZWRpdCxtZW51OmRlbCxyb2xlczpkZWwsYWRtaW4sc3RvcmFnZTpsaXN0LGpvYjplZGl0LGRlcGxveUhpc3Rvcnk6bGlzdCx1c2VyOmRlbCxzZXJ2ZXI6bGlzdCxkaWN0OmFkZCxkZXB0Omxpc3QsdGltaW5nOmFkZCxqb2I6bGlzdCxkaWN0OmRlbCxkaWN0Omxpc3QsYXBwOmxpc3Qsam9iOmFkZCxkYXRhYmFzZTpsaXN0LHRpbWluZzpsaXN0LGRlcGxveTpsaXN0LHJvbGVzOmFkZCx1c2VyOmFkZCxwaWN0dXJlczpsaXN0LG1lbnU6ZWRpdCx0aW1pbmc6ZWRpdCxtZW51Omxpc3Qsc3RvcmFnZTpkZWwscm9sZXM6bGlzdCxtZW51OmFkZCxqb2I6ZGVsLHVzZXI6ZWRpdCxyb2xlczplZGl0LHRpbWluZzpkZWwsZGljdDplZGl0LHNlcnZlckRlcGxveTpsaXN0LGRlcHQ6ZGVsIiwiZXhwIjoxNTgxOTU0NTM3fQ.FRDSUeMqV64gCK4UD7iFGWkPno-GW53Ibz29aUFeaH-f4LMiicelgHmQ7lkDuRO_WEHdTXZjJFRWQiW80mmsUg
< Date: Mon, 17 Feb 2020 14:02:18 GMT
< Server: PERL
< Content-Type: application/json;charset=UTF-8
{"content":[{"create_time":"2020-02-17 17:19:46","id":1,"ip":"1.1.1.100","name":"CC-DC1-NZX-S1","pwd":"cisco","type":"switch","user_name":"cisco"},{"create_time":"2020-02-17 17:19:53","id":2,"ip":"1.1.1.1","name":"CC-DC1-NZX-S1","pwd":"cisco","type":"switch","user_name":"cisco"}],"totalElements":24}
with vue_dev env need the server side support options method
[2020-02-18 19:07:35.58702] [2511] [debug] [69f30b6c] 200 OK (0.001815s, 550.964/s)
[2020-02-18 19:07:36.19296] [2511] [debug] [f4101b49] OPTIONS "/mojo/devices"
[2020-02-18 19:07:36.19325] [2511] [debug] [f4101b49] Routing to controller "FirewallManager::Controller::Device" and action "options"
[2020-02-18 19:07:36.19351] [2511] [debug] [f4101b49] 200 OK (0.000547s, 1828.154/s)
[2020-02-18 19:07:36.19753] [2511] [debug] [54488097] GET "/mojo/devices"
[2020-02-18 19:07:36.19791] [2511] [debug] [54488097] Routing to controller "FirewallManager::Controller::Device" and action "get"
$VAR1 = 'SELECT * FROM device_info ORDER BY id desc LIMIT 10, 10';