zoukankan      html  css  js  c++  java
  • vue中mock数据

    首先 npm install mockjs
    npm install vue-axios --save
    npm install qs.js --save
    
    //main.js
    import Vue from 'vue'
    import axios from 'axios'
    Vue.prototype.$http = axios   //全局注册,使用方法为:this.$http
    Vue.prototype.qs = qs           //全局注册,使用方法为:this.q
    
    //index.vue
    import Mock from "mockjs";
    export default {
      data() {
        return {
          listTemps:[],
        };
      },
      mounted() {
         // 获取mock数据
        var listTemps = JSON.stringify(this.mockInfo());
        this.$http({
          method: "get",
          url: "/listTemp",
        }).then((res) => {
          this.listTemps = JSON.parse(JSON.stringify(res.data)).data;
          console.log(this.listTemps);
        });
      },
      methods: {
        // mock数据
        mockInfo() {
          var that = this;
          var res = Mock.mock("/listTemp", {
            //按序生成一个list
            "data|5": [
              {
                "Name|+1": [
                  "balala",
                  "balala",
                  "balala",
                ], 
                "number|+1": ["4812", "8201", "3412"], 
                "all|+1": ["16:20:15", "18:52:09", "08:44:21"], 
              },
            ],
          });
          return res;
        },
      },
    };
    </script>
  • 相关阅读:
    Linux:Day45(下)
    Linux:Day45(上)
    Linux:Day44(下)
    彻底理解JDK异步
    Ribbon是什么?
    RocketMQ学习笔记(一)eclipse版的quickstart
    线性表的遍历
    八皇后问题
    汉诺塔
    servlet的url-pattern规则
  • 原文地址:https://www.cnblogs.com/minghan/p/13864103.html
Copyright © 2011-2022 走看看