首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FiveM NUI普通API请求

FiveM NUI普通API请求
EN

Stack Overflow用户
提问于 2022-03-18 14:08:04
回答 1查看 482关注 0票数 0

我试图在Vue3端的FiveM NUI中使用javascript发出一个正常的get请求。在chrome中,一切都很好,但是如果我在FiveM中打开页面,就不会加载任何内容。

代码语言:javascript
复制
fetch("http://xxx.xxx.xxx.xxx:xxxx/postinserat", {
   method: "POST",
   headers: {'Content-Type': 'application/json'}, 
   body: JSON.stringify(data)
}).then(res => {
   console.log("Request complete! response:", res);
   this.titel = "";
   this.beschreibung = "";
   this.telefonnummer = "";
   this.preis = "";
   this.currentPage = 0;
   this.getInserate();
});
EN

回答 1

Stack Overflow用户

发布于 2022-06-17 16:23:47

默认情况下,Fivem没有fetch函数,所以您必须将其安装到槽(Node.js)。

使用npm i node-fetch@2

  • Add将
  • 安装节点-获取v2到您的代码的最上面:const fetch = require("node-fetch");

我们使用v2,因为最新的fetch是v3,它使用无法使用require的ES模块。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71528279

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档