最近移动端项目用到的一些不常见的技巧:直接在vue-cli3中上传webpackServer代理首先,在.env.development文件中设置VUE_APP_baseApi=/api其次,在vue.config.js文件中设置devServer:{proxy:{'/api':{target:'http://xxx/api',changeOrigin:true,ws:true,pathRewrite:{'^/api':''}}}}日期格式(yyyy-mm-ddhh:mm)dateFormatter(val){constYYYY=val.getFullYear()constMM=val.getMonth()+1<10?"0"+(val.getMonth()+1):val.getMonth()+1;constDD=val.getDate()<10?"0"+val.getDate():val.getDate();consthh=val.getHours()<10?"0"+val.getHours():val.getHours();constmm=val.getMinutes()<10?"0"+val.getMinutes():val.getMinutes();return`${YYYY}-${MM}-${DD}${hh}:${mm}:`},日期减法计算(y年m月d日h时m分)getRemainderTime(val){letrunTime=nullrunTime=parseInt(val)/1000;让year=Math.floor(runTime/86400/365);运行时间=运行时间%(86400*365);让我th=Math.floor(runTime/86400/30);运行时间=运行时间%(86400*30);让day=Math.floor(runTime/86400);运行时间=运行时间%86400;让hour=Math.floor(runTime/0);runTime=runTime%3600;让分钟=Math.floor(runTime/60);运行时间=运行时间%60;让第二=运行时间;//console.log(年,月,日,时,分,秒);this.countHour=parseInt(val)/1000/3600返回`${year?year+'year':''}${month?month+'month':''}${day?day+'day':''}${hour?hour+'hour':''}${minute?minute+'minute':''}`},音频流mp3格式convertToMp3(wavDataView){//获取wav头信息constwav=lamejs.WavHeader.readHeader(wavDataView);//其实这里不需要读取wav头信息,毕竟有对应的config配置const{channels,sampleRate}=wav;constmp3enc=newlamejs.Mp3Encoder(channels,sampleRate,128);//获取左右声道数据constresult=recorder.getChannelData()constbuffer=[];constleftData=result.left&&newInt16Array(result.left.buffer,0,结果.left.byteLength/2);constrightData=result.right&&newInt16Array(result.right.buffer,0,result.right.byteLength/2);constremaining=leftData.length+(rightData?rightData.length:0);constmaxSamples=1152;for(leti=0;i
