How vue.js loads local json files
This article mainly introduces the vue.js how to load the local json file related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this vue.js how to load the local json file article will have a harvest, let's take a look.
The whole project is packaged by webpack. The specific project structure is as follows:
1: here are the packaged files
2: we find bulid > dev-server.js and open it
3: add this code to it, about 17 lines).
Var app = express () / / add var appData = require ('.. / data.json'); var seller = appData.seller;var goods = appData.goods;var ratings = appData.ratings; var apiRoutes = express.Router (); apiRoutes.get ('/ seller',function (req,res) {res.json ({errno:0, data:seller});}); apiRoutes.get ('/ goods',function (req,res) {res.json ({errno:0, data:goods})) }); apiRoutes.get ('/ ratings',function (req,res) {res.json ({errno:0, datta:ratings});}); app.use ('/ api',apiRoutes)
4: usage:
You can enter http://localhost:8080/api/seller or http://localhost:8080/api/goods or http://localhost:8080/api/ratings in the browser address bar to view the data.
Because the loaded json data is unformatted and looks messy, we can use Google's extension JSONView.
Post the page that reads the data
This is the end of the article on "how vue.js loads local json files". Thank you for reading! I believe you all have a certain understanding of "how vue.js loads local json files". If you want to learn more, you are welcome to follow the industry information channel.