Vue.js Learning Note (ii): How to load a local JSON file

Source: Internet
Author: User

In the process of project development, because we can't interact with the data in the background, we can build a fake data file (such as Data.json) into the project folder so that we can imitate the background data for development. However, how to introduce a local JSON file in a Vue.js project, the following steps are posted. (The project is now packaged by Webpack).

The whole project is packaged by Webpack, and the specific steps are searched online. The specific project structure is as follows:

1: We find bulid>dev-server.js, then open

2: Add this code to the inside.

var app = Express () var appData = require ('.. /data.json '); var seller = Appdata.seller;var goods = Appdata.goods;var Ratings = Appdata.ratings;var Apiroutes = Express.R Outer (); 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);

3: How to use:

You can fill in the browser address bar Http://localhost:8080/api/seller or http://localhost:8080/api/goods or http://localhost:8080/api/ Ratings viewing data

Vue.js Learning Note (ii): How to load a local JSON file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.