vue3+typescript:为表格生成唯一的Key/No
一、思路:定位到该表格
公司、用户、app、项目、路由、表格索引
通过以上信息确保生成的key有规则,且唯一
"{
companyId:'001',
userId:'002',
appId:'003',
project:'snow-pc',
path:'policy/list',
index:'001'
}"
二、注意事项
1、字符串最外层用“”
2、内部-key:无引号
3、内部-value:单引号
4、replace(/\s+/g, '') 去掉所有空格
目的 生成的key保持一致
三、MD5工具
在线工具
MD5生成 - 记灵工具
npm插件
import md5 from 'js-md5'md5(word)
四、集成为一个方法
放在utils文件
url地址参考:https://www.snow.com/snow-pc/#/crm/listimport md5 from 'js-md5'export function tableNo (_this, index) {const key = {companyId: _this.$store.state.companyId,userId: _this.$store.state.userId,appId: _this.$store.state.appId,project: location.pathname,path: _this.$route.fullPath,index: index}return md5(JSON.stringify(key).replace(/\s+/g, ''))
}