本文介绍了IONIC 2 中的图像在哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用 Ionic 2.我在 app 中创建了一个 img 文件,它是一个文件 logo.png.所以我创建了以下代码:

I am just getting started with Ionic 2. I have created an img file in app inside it is a file logo.png. So I have created the following code:

CSS:

.getting-started {
  .logo {
      background-image: url(./img/logo.png);
  }
}

html:

  <ion-col offset-33 width-33 class="logo"><h1>Logo</h1></ion-col>
  <h3>Welcome to your first Ionic app!</h3>

</ion-content>

我知道 css 正在工作,就像我切换背景颜色一样,我得到了预期的结果.但是,我没有得到任何背景图像,只有指定的徽标文本.我应该把图像文件放在哪里?

I know the css is working, as if I toggle the background color, I get the expected results. However, I don't get any background image, just the Logo text specified. Where should I have put the image file?

推荐答案

EDIT:从 Ionic 2 RC 0 开始,放置图像的正确位置是 src/assets/img/ 并且引用图像的正确代码是 .请参阅 Ionic 的 更改日志 RC0(特别是 #28).

EDIT: As of Ionic 2 RC 0, the correct place to put your images is in src/assets/img/ and the correct code to reference the image is <img src="assets/img/myImg.png">. Please see Ionic's change log for RC0 (specifically #28).

截至目前,使用官方 Drifty Co. Ionic 2 Conference App 作为参考,图像应该放在 www/ 目录中.

As of right now, using the official Drifty Co. Ionic 2 Conference App as a reference, images should be placed inside of the www/ directory.

在我当前的 Ionic 2 应用程序中,图像位于 www/img/logo.png 并在 app/pages/page_name/page_name.html 中引用作为 <img src='img/logo.png'>,它就像一个魅力.

In my current Ionic 2 app, an image is located at www/img/logo.png and it is referenced in app/pages/page_name/page_name.html as <img src='img/logo.png'> and it works like a charm.

目前使用:

  • ionic-angular v2.0.0-beta.6 (package.json)
  • 离子原生 ^1.1.0 (package.json)
  • ionic-cli v 2.0.0-beta.25(已安装的 CLI)

这篇关于IONIC 2 中的图像在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 14:01