1. js驼峰与下划线相互转化
// 下划线转换驼峰
function toHump(name) {
return name.replace(/\_(\w)/g, function(all, letter){
return letter.toUpperCase();
});
}
// 驼峰转换下划线
function toLine(name) {
return name.replace(/([A-Z])/g,"_$1").toLowerCase();
}
2.导出表格
// 导出表格
exportExcel () {
let url = `${baseUrl}/admin_web/export_data_project_report`;
if (this.queryInfo.project) url = url + "?project_name=" + this.queryInfo.project;
if (this.queryInfo.date) url = url + "&start_time=" + this.queryInfo.date[0] + "&end_time=" + this.queryInfo.date[1];
window.open(url, '_blank')
}
// window.open(this.indexro,'_blank') // 在新窗口打开外链接
// window.location.href =this.indexro; //在本页面打开外部链接
3. 控制子组件的显示与隐藏
computed: {
groupRolesDialogVisible: {
get () {
return this.rolesDialogVisible;
},
set (val) {
this.$emit('update:rolesDialogVisible', val);
},
},
},
4.截取字符串
id = row.url.substring(row.url.indexOf('=') + 1, row.url.length);
5.Promise.all的用法
initCreateEnv () {
let templateId = this.$route.query.templateId;
if (!Array.isArray(templateId)) {
templateId = [templateId];
}
const list = [];
templateId.forEach(tplId => {
list.push(initCreateEnv(tplId));
})
Promise.all(list).then(res => {
if (res.length > 0) {
this.templateList = [...res];
this.userInfo = res[0].userInfo;
}
}, (err) => {
this.$message({
type: 'error',
message: err.errmsg,
});
console.error(err);
})
},
6. 时间转换
import moment from 'moment'
moment(time).format('YYYY-MM-DD');