【干货】接口公共方法(字典表查询)

公共方法

import * as api from '@/api/commonAjax.js';

//获取字典表
const getAjaxListCommon=function(mm,backfun) {
    let ajaxFun=""
    if(mm==1){//字典表1
        ajaxFun="getAjax1"
    }else if(mm==2){//字典表2
        ajaxFun="getAjax12"
    }
    api[ajaxFun]({}).then((res)=>{
        if(res.code==200){
            let copy=JSON.parse(JSON.stringify(res.data))
            backfun(copy)
        }
    })
}

后台方法

import createService from '@utils/request.js';
const commonUrl = createService("http://111.111.111.111:9999");

//字典表1
export function getAjax1(params) {
    return commonUrl({
        url: '/ajaxAddr',
        method: 'get',
        params:params,
    });
}
//字典表2
export function getAjax2(data) {
    return commonUrl({
        url: '/ajaxAddr66',
        method: 'post',
        data,
    });
}

使用步骤

步骤1:
    将【公共方法】添加至./src/assets/commonOpt.js(新建脚本)
步骤2:
    将【后台方法】添加至./src/api/commonAjax.js(新建脚本)
步骤3:
    【main.js】添加以下代码:
        import * as commonOpt from '@/assets/commonOpt.js';
        Vue.prototype.$commonOpt = commonOpt;
步骤4:
    使用公共方法:
        this.$commonOpt.getAjaxListCommon(1,function(list){ 
            console.log(list) 
        })

最近更新

  1. TCP协议是安全的吗?

    2023-12-05 19:08:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-05 19:08:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-05 19:08:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-05 19:08:01       18 阅读

热门阅读

  1. 数据结构基础(不带头节点的单向非循环链表)

    2023-12-05 19:08:01       36 阅读
  2. 数据结构基础(带头节点的双向循环链表)

    2023-12-05 19:08:01       42 阅读
  3. Python函数(一)

    2023-12-05 19:08:01       42 阅读
  4. JWT 认证机制

    2023-12-05 19:08:01       29 阅读
  5. 【Node.js】笔记整理 1 - 基础知识

    2023-12-05 19:08:01       38 阅读
  6. 学习c#的第二十四天

    2023-12-05 19:08:01       35 阅读