vue模版中 根据返回的id去解析,id对应的name

需求:根据返回的id去解析,id对应的name

   <template slot="gs" slot-scope="{ row }">
        //传参把当前id传过去
    {{ guishu(row.province_id, row.city_id, row.district_id) }}
   </template>


    //拿当前id去和sz数组中的数据对比
    guishu(province_id, city_id, district_id) {
      let zhi = "";
      let hanshi = "";
      let shu = "";
      this.sz.forEach((res, index) => {
        if (province_id == res.id) {
          zhi = res.name;
        }
        if (city_id == res.id) {
          hanshi = res.name;
        }
        if (district_id == res.id) {
          shu = res.name;
        }
      });
      return zhi + "-" + hanshi + "-" + shu;//拼接下根据id返回省市区
    },
posted @ 2021-11-22 11:07  喜欢Tb  阅读(113)  评论(0)    收藏  举报  来源