vue json传参网络请求

vue.confog.js

module.exports = {
   lintOnSave: false,
   outputDir: "dist",
   assetsDir: "static",
   productionSourceMap: false,
   publicPath: "./",
   devServer: {
     open: true,
     host: "0.0.0.0",
     port: 8080,
     hotOnly: false,
     proxy: {
       api: {
         //服务器端接口地址
         // http://192.168.10.107:8080/yzl/user/jsontype/2
         // target: "https://elm.cangdu.org/",
         target: "http://192.168.10.109:8080",
         //
         ws: true,
         //是否跨域
         changeOrigin: true,
         pathRewrite: {
           "^/api": "/",
         },
       },
     },
   },
 };
 

2http-service

import axios from axios;

//拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    if (response.status == 200) {
        return response.data;
    }
}, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
});
export default {
    // http://192.168.10.109:8080/yzl/user/adduser
    // {"userName":"金贵江","password":"123c","phone":"159888","age":"23","email":"345","sex":"男"}
    // http://192.168.10.109:8080/yzl/user/queryuser
    // {"userName":"金贵江","password":"123a"}
    PostQueryuser (datas) {
        // let datas = {userName:userName,password:password};
        return   axios({
            headers: {
              "Content-Type": "application/json;",
            },
            method: "post",
             dataType: jsonp,
            transformRequest: [
              function(data) {
                // 对 data 进行任意转换处理
                console.log(data);
                return JSON.stringify(datas);
              },
            ],
            url: "api/yzl/user/queryuser",
            params: datas,
          })
    },
    PostAdduser () {
        return  axios({
            url: api/yzl/user/adduser,
            method: post,
            // params: wxuser
          })
    },
    repairSign() {
        return  axios({
            url: api/v2/login,
            method: post,
            // params: wxuser
          })
    },
    //登陆
    postRegistered() {
        return axios.post(api/v2/login)
    },
    //首页数据加载
    getHome() {
        return axios.get(api/show/)
    },
    //数据详情页

    getDetail(id) {
        return axios.get(api/show/details/, { params: { id } });
    },
    //最新专题
    getTopic() {
        return axios.get(api/v1/web/index_card)
    },
    //详情
    getTopicDetail(id) {
        return axios.get(/api/Latest/details/, { params: { id } })
    },
    //获取精品专题/咨询攻略头部信息
    getStrategy() {
        return axios.get(/api/strategy/)
    },
    //获取精品专题/咨询攻略头部信息详情
    getStrategyDetail(id){
        return axios.get(/api/strategy/details/, { params: { id } })
    }
}

3

   get() {
      let datas = {userName:"金贵江",password:"123a"};
      axios({
        headers: {
          "Content-Type": "application/json;",
        },
        method: "post",
         dataType: jsonp,
        transformRequest: [
          function(data) {
            // 对 data 进行任意转换处理
            console.log(data);
            return JSON.stringify(datas);
          },
        ],
        url: "api/yzl/user/queryuser",
        params: datas,
      })
        .then(function(res) {a
       console.log(res);
        })
        .catch(function(error) {a
          console.log(error);
        });
    },
 data() {
    return {
      a: { userName: "金贵江", password: "123c" },
}}

     PostQueryuser(a) {
      // let datas = {userName:"金贵江",password:"123a"};
     http.PostQueryuser(a).then(res=>{
       console.log(res);
     })

 

vue json传参网络请求

上一篇:[横向移动]ms14-068 复现


下一篇:068.Python框架Django之DRF视图集使用