SoFunction
Updated on 2025-04-05

vue-resource + json-server to simulate data

This article introduces vue-resource + json-server simulation data and shares it with you, as follows:

1. Installation

npm install vue-resource --save
npm install json-server --save

2. Configuring and using vue-resource

// 
import VueResource from 'vue-resource'
(VueResource)
   this.$('api/getNewsList')
    .then(function (data) {
     (data)
    }, function (err) {
     (err)
    })

3. Configure json-server

// 
var jsonServer = require('json-server')
var apiServer = ()
var apiRouter = ('')
var middlewares = ()

(middlewares)
('/api', apiRouter)
(port + 1, function () {
 ('JSON Server is running')
})
// config/
dev:{
  ...
  proxyTable: {
   '/api/': 'http://localhost:8081/'
  },
  ...
}

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.