从' ../ src / images'导入LocalImg

时间:2017-05-30 10:08:55

标签: react-native ecmascript-6

从' ../ src / images'

导入LocalImg

错误:

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:3)

它清楚地表明你没有包含index.js文件,所以它不确定你要从那么多文件导入什么。你需要解决方案

  1. 使用require只获取您需要的文件,例如,如果我需要 ad1.png ,我将按以下方式执行此操作
  2.   

    const ad1 = require('../ src / images / ad1.png');

    1. 会在images文件夹中添加一个index.js文件并执行类似这样的操作
    2. //index.js
      
      export const ad1 = require('./images/ad1.png');
      .
      .
      .
      export const ad2= require('./ad2.png'); 
      export const ad3 = require('./ad3.png'); 
      export const ad4 = require('./images/ad4.png');
      
      
      //in other file I should import like
      
      import {ad1, ad2, ad3....} from '..src/images';