Phonegap 是否支持根相对路径?最佳做法是什么? [英] Does Phonegap support root relative path? What are the best practices?

查看:17
本文介绍了Phonegap 是否支持根相对路径?最佳做法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读 PhoneGap on iOS 后,我真的很困惑资产的绝对路径 URL并有几个问题:

  • Phonegap 是否支持根相对路径?例如,用于混合移动开发的 Ionic 框架 在他们的 示例:

Phonegap 路径的最佳实践是什么?

What are the best practices for Phonegap's path?

推荐答案

基本上在电话间隙开发中,与您的代码相关的所有内容都位于 www 文件夹中.

Basically in phone gap development everything that concerns your code resides in the www folder.

-myApp
   -www
      -index.html
      -img
      -js
      -css
      -libraries
      -templates

最好将文件称为 js/file.jscss/file.css,即相对于 index.html.

The best would be to just refer the files as js/file.js and css/file.css i.e relative to index.html.

根相对路径可能会因平台而发生冲突,因此会带来不必要的麻烦.

Root relative paths may conflict depending on the platform and thus would be a unnecessary hassle.

根相对路径:

做这样的事情:

<link href="/css/app.css">

如果您设置了本地服务器并将 myApp/www 文件夹设置为根目录,这将在您的浏览器中工作.

This will work in your browser if you have a local server setup and have set your myApp/www folder as the root.

但是当您在cordova中构建您的应用程序并在您的手机上对其进行测试时,它会显示错误,因为它没有对该服务器根目录的任何引用,而是将其引用为file:///.

But when you build your app in cordova and test it on your phone, it will display incorrectly as it does not have any reference to that server root and will reference it as file:///.

绝对路径

绝对路径需要您提及完整地址.创建应用程序时,您的代码位于 myApp/www 文件夹中.但是当您构建应用程序(假设为 android)时,它会移动到 platforms/android/assets/www 文件夹.所以你的绝对路径又会出错.

An absolute path would require you to mention the complete address. When you are creating your app, your code resides in the myApp/www folder. But when you build the app(assuming android), it is moved to the platforms/android/assets/www folder. So your absolute paths will again be wrong.

远程服务器

您的应用程序显然与远程服务器交互.如果您将图像存储在远程服务器上,则必须在应用程序中使用绝对路径引用它们.

Your app obviously interacts with a remote server . If you store your images on your remote server, then you must refer to them with absolute paths in your application.

这篇关于Phonegap 是否支持根相对路径?最佳做法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆