vue.js +axios mock数据

在main.js中

import axios from 'axios'
Vue.prototype.$ajax = axios

 

webpack.dev.conf.js中

 

const express = require('express')
const app = express()

const goodsData = require('./../goods.json')
在devServer中
  before(app) {
    app.get('/goods',(req,res) => {
      res.json(goodsData)
   })
  }

 

在GoodsList组件中

 

data () {
    return {
      goods: []
    }
  },
  created () {
    this.$ajax.get('/goods').then((res) => {
       const data = res.data
       this.goods = data.result
     })
  },

 

相关文章:

  • 2021-09-13
  • 2022-02-22
  • 2021-05-21
  • 2021-11-17
  • 2021-06-29
  • 2021-09-01
  • 2021-04-09
猜你喜欢
  • 2022-12-23
  • 2021-10-05
  • 2022-01-07
  • 2022-12-23
  • 2021-08-25
  • 2022-12-23
  • 2021-04-28
相关资源
相似解决方案