Mini program introduces json file data

Today, when writing a small program, I need to introduce a json file, and I will record it here.

1. Create files

Create a data folder and a foods file (here is the canteen information, the name will vary depending on your needs), specifically for storing data.

2. Change the json file to js

Put the content of the json file that needs to be imported into the beginning of the newly created foods.js file and add export default

 3. Introduction of logic layer

import foods from "../../data/foods";  

  data: {
    shop1:foods[0] //具体数据看自己的json内容
  }

 Check whether the debugger AppData is successfully introduced.

 4. View layer display

In fact, the data has been obtained, and the view layer is very simple. Just write the specific style according to your own needs. I will only make a simple demonstration here.

Guess you like

Origin blog.csdn.net/ZcRook1e/article/details/131265081