vue封装axios请求列表数据加载到选择框中

入职一个半月..对业务不是很熟悉。但是感觉这么写获取字典表数据还是挺好的。哈哈

 

方法二: 调用仅仅需要传入Key值即可。如果是其他方法可以做相应的修改。

 

export const setDicValue2=(dicInfoKey) => {
  let _this=this
  let p =new Promise(( resolve => {
    axios.post(config.GET_DICINFO_BYKEY, {
      keyword: dicInfoKey
    })
      .then(function (res) {
        if (res.data.status == "200") {
          resolve(res.data.data)
        }
        else {
          _this.$message({
            type: "error",
            message: res.data.message,
            duration: "1000"
          })

        }

      })
      .catch(function (res) {
        _this.$message({
          type:"error",
          message:res.message,
          duration:"1000"
        })
      });
  } ))
  return p
}

请求字典:即同一url。根据不同的参数返回值列表,vue可以将数据响应式的渲染到视图中。

//key为字典的key值,value为data对象中的数组名称,sourceList=[]
let getDicKV={
  "PRODUCE_SOURCE":"sourceList",
  "PROCEDURE_TYPE":"procedureList",
  "PLANNING_PLAN_STATUS":"statusList",
  "PRODUCE_TYPE":"produceTypeList"
}
/*
* 遍历kv键值对,依次设置列表值
* */
for(let key in getDicKV){
  axiosPostLoadDicDataList(_this,key,getDicKV[key])
}

 

/*
* 加载字典列表数据方法
*
* _this为调用对象
* dicInfoKey为key值
* listname为字典数组名称
* isFour判断数据是否在res响应流的四级菜单中,True/false
* 调用示例  helpTools.axiosPostLoadDicDataList(_this,"PRODUCE_TYPE","checkList")
* */
export const axiosPostLoadDicDataList = (_this,dicInfoKey,listname,isFour) => {
  axios.post(config.GET_DICINFO_BYKEY, {
    keyword: dicInfoKey
  })
    .then(function (res) {
        if (res.data.status == "200") {
          if (!isFour) {
              _this[listname] = res.data.data

          }
          else {
            _this[listname] = res.data.data.row
          }
        }
        else {
          _this.$message({
            type: "error",
            message: res.data.message,
            duration: "1000"
          })

        }

    })
    .catch(function (res) {
      _this.$message({
        type:"error",
        message:res.message,
        duration:"1000"
      })
    });
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值