Detailed usage steps of Mockjs in angular

1. Install the mock

npm install mockjs

2. Create an environment folder in the src directory and create a ts file with the following content: 

3. Introduce the environment file in the main.ts file and declare require, otherwise the import path will report an error

4. Create a mock file and create an index.js folder. The steps are as follows:

 5. The component imports HttpClient, then injects it in the constructor, and finally uses it in the declaration cycle. res must be specified as any, otherwise the internal list cannot be called

6. The page layout is as follows: it must be judged by if, otherwise the error of length and 0 will be reported, because it is caused by asynchronous reasons

7. The effect is as follows:

 

Guess you like

Origin blog.csdn.net/qq_72760247/article/details/130305432