【问题标题】:Ionic 4 app shows api data in browser but on device it doen't shows api dataIonic 4 应用程序在浏览器中显示 api 数据,但在设备上它不显示 api 数据
【发布时间】:2020-04-09 15:24:07
【问题描述】:

当我运行 Ionic 4 应用程序时,浏览器会显示 api 数据,但是当我在 android 设备上运行相同的应用程序时,它不会显示 api 数据。
我使用 Laravel 作为后端,从中获取 api 数据。
离子信息是 -

Ionic:

   Ionic CLI                     : 6.5.0 (C:\Users\LENOVO\AppData\Roaming\npm\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 4.1.1
   @angular-devkit/build-angular : 0.803.26
   @angular-devkit/schematics    : 8.3.26
   @angular/cli                  : 8.3.26
   @ionic/angular-toolkit        : 2.2.0

Cordova:

   Cordova CLI       : not installed
   Cordova Platforms : android 7.1.4
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 4 other plugins)

Utility:

   cordova-res : not installed
   native-run  : 1.0.0

System:

   NodeJS : v12.16.1 (C:\Program Files (x86)\nodejs\node.exe)
   npm    : 6.13.4
   OS     : Windows 10

我真的被困在这里了……

【问题讨论】:

  • 您一定遇到了一些错误,很可能是关于 CORS。尝试使用 chrome 检查您的应用。
  • 我在 chrome 上遇到错误,因为 --- 从源 'localhost:8100' 访问 XMLHttpRequest 已被 CORS 策略阻止:没有 'Access-Control-Allow-Origin' 标头出现在请求的资源上。但是在启用 chrome CORS 时此错误已删除..
  • 但是当我在 android 设备上运行这个应用程序时,它什么也没显示.. 应用程序数据变为空白..
  • 最可能的问题是 CORS,您需要后端 api 来允许来自您的来源的请求。
  • 请指导我关于这个先生..我使用 Laravel 5 和 mysql 作为后端..

标签: ionic-framework ionic4


【解决方案1】:

你的问题是 Cors 你可以在 laravel 中安装中间件来避免这个问题 或者您可以在 chrome disable securite 中测试您的应用程序

尝试运行:

chrome.exe --user-data-dir="C://Chrome 开发会话" --disable-web-security

在这个 chrome 中测试你的应用程序,让我知道

【讨论】:

  • 该应用在 chrome 上运行,但无法在 android 设备上显示数据....
猜你喜欢
  • 2018-12-01
  • 2017-06-29
  • 2012-02-17
  • 2021-03-07
  • 2016-08-22
  • 1970-01-01
  • 1970-01-01
  • 2021-12-11
  • 2021-06-28
相关资源
最近更新 更多