nuxt.js在asyncData或fetch里面请求的接口报错,在mounted里正常
async fetch({ store }) { await store.dispatch('setSite')
}
报错下面的错误,一打开页面就报这个错误,换个浏览器也是一样
{ Error: getaddrinfo ENOTFOUND 7890 7890:80 at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: '7890',
host: '7890',
port: 80,
config:
{ url: '/index/siteinfo',
method: 'get',
headers:
{ Accept: 'application/json, text/plain, */*',
connection: 'keep-alive',
pragma: 'no-cache',
'cache-control': 'no-cache',
'sec-ch-ua':
'" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"',
'sec-ch-ua-mobile': '?0',
'upgrade-insecure-requests': '1',
'user-agent':
'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'navigate',
'sec-fetch-dest': 'document',
'accept-encoding': 'gzip, deflate',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,co;q=0.7',
cookie:
'Hm_lvt_ef07bef2da496082a7b3f5853c998d64=1632447858,1632616457,1632725914,1632792192',
host: 'localhost:8000' },
baseURL: 'http://localhost:8000/pc',
transformRequest: [ [Function] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 22347,
withCredentials: true,
adapter: [Function: httpAdapter],
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
'axios-retry': { retryCount: 3, lastRequestTime: 1632969900119 },
data: undefined },
这样写正常的
mounted() { this.$store.dispatch('setSite')
}
回答:
host 7890是什么鬼?️ 换0.0.0.0试试?
以上是 nuxt.js在asyncData或fetch里面请求的接口报错,在mounted里正常 的全部内容, 来源链接: utcz.com/p/936222.html