loading json data from local file into React JS

前端 未结 8 1762
无人及你
无人及你 2020-11-30 00:33

I have a React component and I want to load in my JSON data from a file. The console log currently doesn\'t work, even though I\'m creating the variable data

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 00:43

    The simplest and most effective way to make a file available to your component is this:

    var data = require('json!./data.json');
    

    Note the json! before the path

提交回复
热议问题