日志

彼岸花开,蓝蝶依肩。

(1)

后端返回的数据一般都是直接new Date()的Long类型时间。需要自己手写转换工具。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* 时间格式化工具
* 把Long类型的1527672756454日期还原yyyy-MM-dd格式日期
*/
export function dateFormat(longTypeDate){
let dateTypeDate = "";
let date = new Date();
date.setTime(longTypeDate);
dateTypeDate += date.getFullYear(); //年
dateTypeDate += "-" + getMonth(date); //月
dateTypeDate += "-" + getDay(date); //日
return dateTypeDate;
}
//返回 01-12 的月份值
function getMonth(date){
let month = "";
month = date.getMonth() + 1; //getMonth()得到的月份是0-11
if(month<10){
month = "0" + month;
}
return month;
}
//返回01-30的日期
function getDay(date){
let day = "";
day = date.getDate();
if(day<10){
day = "0" + day;
}
return day;
}

(2)

es6importexport的一些细节

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// counter.js
import {a} from './my';
console.log('谕');
console.log(a);

// my.js
console.log('宋');
export var a = '我喜欢你啊,你喜欢我吗';
console.log('俊');

//运行结果
//宋
//俊
//谕
//我喜欢你啊,你喜欢我吗

看看编译后的counter.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//#----------------mod start----------------

void function (module, exports){
window["60ae5ba7"] = {};

"use strict";
// my.js
console.log('宋');
window["60ae5ba7"].a = '我喜欢你,你喜欢我吗';
console.log('俊');

}({exports:{}}, {})


//#----------------mod end----------------

//#----------------mod start----------------

void function (module, exports){
window["3d4fdd69"] = {};

"use strict";
// counter.js
var my_1 = window["60ae5ba7"];
console.log('谕');
console.log(my_1.a);
1
2
3
4
5
6
7
8
//把console.log(a)去掉
// counter.js
import {a} from './my';
console.log('谕');
// console.log(a);

//运行结果
//谕

为什么只输出一句了?

ES6的模块加载机制是“静态加载”,执行import命令是在编译期间完成,生成一个静态引用。等到需要的时候,再到模块里面去取值。

那为什么之前的顺序是宋俊谕我喜欢你,你喜欢我吗,而不是先输出谕呢?

仅为猜测:在编译的时候,发现了后面有使用到a的地方,就在运行时遇到import的地方直接执行了模块的代码。

(3)

WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).

解决

方式一 webpack中添加如下配置

1
2
3
performance: {
hints:false
}

方式二 webpack中添加如下配置

1
2
3
4
5
6
7
8
9
10
performance: {
hints: "warning", // 枚举
maxAssetSize: 30000000, // 整数类型(以字节为单位)
maxEntrypointSize: 50000000, // 整数类型(以字节为单位)
assetFilter: function(assetFilename) {
// 提供资源文件名的断言函数
return assetFilename.endsWith('.css') || assetFilename.endsWith('.js');

}
},
-------------要说再见啦感谢大佬的光临~-------------