代码之家  ›  专栏  ›  技术社区  ›  Adam Beleko

在Vue Native中添加静态图像资源

  •  0
  • Adam Beleko  · 技术社区  · 6 年前

    我知道为了在react native中添加静态图像资源,图像必须是静态已知的。具体做法是:

    var icon = this.props.active
      ? require('./my-icon-active.png')
      : require('./my-icon-inactive.png');
    <Image source={icon} />;
    

    在vue native中,与在react native中一样,使用

    <image
      :source="{require('./my-icon.png')}"
    />
    

    不会工作,因为静态图像不是静态已知的。 如何使图像在Vue本机中静态显示?

    0 回复  |  直到 6 年前
        1
  •  2
  •   Ashley van Laer    5 年前

    在Vue Native中,您需要这样编写:

    <image
    :source="require('./my-icon.png')"
    />
    

    {} 之间 ""