一、新建mock文件夹

526E4FA0-EBFB-44D5-A3E6-25418F9D7F7A.png

二、配置vue.config.js

  1. const data = require("./mock/index.json");
  2. module.exports = {
  3. devServer: {
  4. port: 8080,
  5. before(app) {
  6. app.get("/cart", (req, res) => {
  7. res.json(data);
  8. });
  9. }
  10. }
  11. }

三、请求数据

  1. mounted(){
  2. axios.get("/cart").then(res=>{
  3. console.log(res)
  4. })
  5. }