公共方法
import * as api from '@/api/commonAjax.js';//获取字典表
const getAjaxListCommon=function(mm,backfun) {let ajaxFun=""if(mm==1){//字典表1ajaxFun="getAjax1"}else if(mm==2){//字典表2ajaxFun="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) })