vue mock数据设置

1.新建mock文件夹

2.添加你需要的数据例如新建商品表goods.json

{
  "status":"0",
  "result":[
    {
        "productId":"10001",
        "productName":"小米6",
        "prodcutPrice":"2499",
        "prodcutImg":"mi6.jpg"
    },
    {
      "productId":"10002",
      "productName":"小米笔记本",
      "prodcutPrice":"3999",
      "prodcutImg":"note.jpg"
    },
    {
      "productId":"10003",
      "productName":"小米6",
      "prodcutPrice":"2499",
      "prodcutImg":"mi6.jpg"
    },
    {
      "productId":"10004",
      "productName":"小米6",
      "prodcutPrice":"2499",
      "prodcutImg":"1.jpg"
    },
    {
      "productId":"10005",
      "productName":"小米6",
      "prodcutPrice":"2499",
      "prodcutImg":"2.jpg"
    },
    {
      "productId":"10006",
      "productName":"小米6",
      "prodcutPrice":"2499",
      "prodcutImg":"3.jpg"
    },
    {
      "productId":"10007",
      "productName":"小米6",
      "prodcutPrice":"2499",
      "prodcutImg":"4.jpg"
    },
    {
      "productId":"10008",
      "productName":"小米6",
      "prodcutPrice":"2499",
      "prodcutImg":"5.jpg"
    }
  ]
}

 2.添加build下的dev-server.js

var goodsData = require('../mock/goods.json')
var router = express.Router()
router.get("/goods", function (req,res) {
  res.json(goodsData)
})
app.use(router)

在.vue页面写个请求

import axios from ”axios"
methods:{
  getGoodsList(){
     axious..get("/goods").then((result)=>{
        var res=result.data
      })
   }
}

  

posted @ 2018-02-22 15:04  开始战斗  阅读(238)  评论(0编辑  收藏  举报