数据字典

export const ROLE_TYPE = [
{ label: '管理员', value: 1 },
{ label: '老板', value: 2 },
{ label: '店长', value: 3 },
{ label: '店员', value: 4 }
]

export const ADMIN_TYPE_VALUE = 1

(port.js)数据从此处获取

1 import {
2   PORT_TYPE,
3   PORT_ONLINE_STATUS,
4   PORT_BIND_STATUS
5 } from "@/constants/port";//在info.vue中引入
    import { formatterGenerator, formatDate } from "@/lib/helper";//在info.vue中引入函数
 
1 export function formatterGenerator(mapper, value) {
2   const item = mapper.find(item => item.value === value)
3   return item ? item.label : '-'
4 }

(helper.js)这里引入处理数据的函数

1  roleFormatter(row) {
2       if (!row) {
3         return
4       }
5       return formatterGenerator(ROLE_TYPE, row.role);
6     },//info.vue

这样反复引入js文件的目的就是避免全部写在组件当中造成文件代码十分庞大,不利于维护。

 find() 方法返回数组中满足提供的测试函数的第一个元素的值。否则返回 undefined

 1 var inventory = [
 2     {name: 'apples', quantity: 2},
 3     {name: 'bananas', quantity: 0},
 4     {name: 'cherries', quantity: 5}
 5 ];
 6 
 7 function findCherries(fruit) { 
 8     return fruit.name === 'cherries';
 9 }
10 
11 console.log(inventory.find(findCherries)); // { name: 'cherries', quantity: 5 }
 1 function isPrime(element, index, array) {
 2   var start = 2;
 3   while (start <= Math.sqrt(element)) {
 4     if (element % start++ < 1) {
 5       return false;
 6     }
 7   }
 8   return element > 1;
 9 }
10 
11 console.log([4, 6, 8, 12].find(isPrime)); // undefined, not found
12 console.log([4, 5, 8, 12].find(isPrime)); // 5

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/find

posted @ 2019-01-24 17:33  山外已有山  阅读(203)  评论(0编辑  收藏  举报