如何在Axios中使用“预连接”和“ dns-prefetch”

问题描述 投票:0回答:1

我如何使用Axios修复此问题,是否有任何参数?

axios.get('/slug', { params })

预连接到必需的来源0.3秒考虑添加preconnectdns-prefetch资源提示以建立与重要第三方起源的早期连接。了解更多。

enter image description here

axios google-chrome-devtools pagespeed nuxt
1个回答
0
投票

全部resource hints只能用作<link>元素上的属性。您可以阅读有关它们的功能以及操作方法的信息,例如here

因此,您无法直接在JavaScript中进行任何操作(当然,除了根据用户操作将属性动态添加到现有链接之外)

如果您要从域https://api.my-app.com使用Axios进行请求,只需将<link rel="preconnect" href="https://api.my-app.com" />包含到页面中就足够了...

© www.soinside.com 2019 - 2024. All rights reserved.