2018年11月

1.  一个从0 ->1 ->2 (->1和2循环的表达式)   a%2 + 1

2. 下载后端传回的二进制流文件

 1 axios.post(url, {}, {responseType: 'blob'}).then(res => {
 2 if (res && res.data) {
 3 var blob = new Blob([res.data], {
 4 type: "application/vnd.ms-excel"
 5 });
 6 var a = document.createElement('a');
 7 a.download = 'template.xlsx';
 8 a.href = window.URL.createObjectURL(blob);
 9 document.body.appendChild(a);
10 a.click();
11 window.URL.revokeObjectURL(a.href);
12 document.body.removeChild(a);
13 } else {
14 window.alert('下载错误!');
15 }
16 });

 

3.点击复制到剪贴板

/* 创建range对象 */
const range = document.createRange();
range.selectNode(element); // 设定range包含的节点对象
/* 窗口的selection对象,表示用户选择的文本 */
const selection = window.getSelection();
if (selection.rangeCount > 0) selection.removeAllRanges(); // 将已经包含的已选择的对象清除掉
selection.addRange(range); // 将要复制的区域的range对象添加到selection对象中
document.execCommand('copy'); // 执行copy命令,copy用户选择的文本

ps.不能复制不连续的区域  如果有这个需求 可以插入临时DOM把想复制的放在一起 复制后再移除

posted on 2018-11-15 16:37  natsu07  阅读(114)  评论(0编辑  收藏  举报