若依移动端Ruoyi-App——字典使用

 1.  引入dict

将若依前后端分离中的dict文件夹拷贝到api的system里

2.在页面中引入方法

   import { getDicts } from "@/api/system/dict/data";

3. 前端

     <span>{ {statusType}}</span>

4.  加载数据字典

export default {
  data() {
    return {
      statusOptions: [],
      .....
...

onLoad(option) {
  this.getDicts("status_type").then(response => {
    this.statusOptions= response.data;
  });
},

5. 读取数据字典显示内容

    //使用find遍历查找,并显示字典值
     let  status=app.statusOptions.find(item=>item.dictValue==res.data.status);
     this.statusType=status .dictLabel

6.  列表显示

     将列表中的数字,遍历直接替换成字典值

                 this.dataList.forEach((self,index) => {
                       let status=this.statusOptions.find(item=>item.dictValue==self.status);
                       self.statusType=status.dictLabel
                  });

猜你喜欢

转载自blog.csdn.net/zhaolulu916/article/details/130057907