zoukankan      html  css  js  c++  java
  • vue main.js 设置

    // The Vue build version to load with the `import` command
    // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
    import Vue from 'vue'
    import App from './App'
    // import VueRouter from './router'
    import VueRouter from 'vue-router'
    import Axios from 'axios'  //引用
    import QS from 'qs'
    import Customers from './components/Customers'
    import About from './components/About'
    import Add from './components/Add'
    import CustomerDetails from './components/CustomerDetails'
    import Edit from './components/Edit'
    
    
    Vue.config.productionTip = false  //阻止启动生产消息,常用作指令。
    
    Vue.use(VueRouter)
    
    Vue.prototype.$axios=Axios  //挂载到原形上
    //axios全局配置
    Axios.defaults.baseURL = 'http://localhost:3000';  // 此处设置全局适用  避免每个页面的接口请求都  用的接口 前缀
    Axios.defaults.headers.post['Content-Type'] = 'application/json';
     //Axios.defaults.headers.post['Content-Type'] = 'x-www-from-urlencoded'; 
    
    
    //拦截器
    
    
    // 添加请求拦截器
    Axios.interceptors.request.use(function (config) {
        // 在发送请求之前做些什么
    
        if(config.method==="post"){  //只有在post请求是 时
            console.log(config.data);
            //config.data=QS.stringify(config.data) ; //如果 后台不接受原声json  格式参数 需要序列化参数,需要安装 QS插件;请求之前对请求参数进行格式转换  转化后  格式user_id=iwen%40qq.com&password=iwen123
            console.log(config.data);
        }
    
        //console.log(config);  //打印网络请求 
        return config;
      }, function (error) {
        // 对请求错误做些什么
        return Promise.reject(error);
      });
    
    // 添加响应拦截器
    Axios.interceptors.response.use(function (response) {
        // 对响应数据做点什么
    //console.log(response)
        if(!response.data){
            return{
                msg:"数据返回不合理"
            }
        }
    
        return response;
      }, function (error) {
        // 对响应错误做点什么
        return Promise.reject(error);
      });
  • 相关阅读:
    leetcode_24. 两两交换链表中的节点
    Mysql大数据量分页优化
    MySQL 默认排序是什么
    spring注入map,spring注入一个接口的多个实现类在map里
    eureka缓存细节以及生产环境的最佳配置
    MySQL 5.7性能调优
    安装后的十个MySQL性能调整设置(版本:5.1、5.5 和5.6)
    docker部署tomcat应用和MySQL数据库
    MySQL热备工具Xtrabackup
    MySQL数据库的冷备方式
  • 原文地址:https://www.cnblogs.com/jinsuo/p/11769123.html
Copyright © 2011-2022 走看看