摘录

我见过春日夏风,秋月冬雪,也曾踏遍南水北山,东麓西岭,可这四季春秋,苍山央水,都不及你瞅我展眉一笑

阅读全文
Git

概述

我们可以把 Git 分成两个部分,一个是远程仓库 Remote Repository,还有一个是本地环境 Development Environment

命令

git clone

阅读全文
图片裁剪

使用方法

1
2
3
4
5
6
7
8
9
10
11
import imageClip from './imageClip.js';

new imageClip({
src: 'data:image/png;base64,',
ok: (data) => {
console.log(data);
},
complete: () => {
// 取消或确认操作回调
}
});
阅读全文
数字滚动特效

使用方法

1
<numberRoll :number="9866.66"></numberRoll>
阅读全文
移动端 px 适配

px 单位转 rem(移动端适配)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// 按照宽度1920或高度1040去换算(1px===1rem)
function setSize() {
let screenWidth = document.documentElement.clientWidth
let screenHeight = document.documentElement.clientHeight
let scaled = 1920 / 1040
let currentFontSize = 12
if (scaled > screenWidth / screenHeight) {
currentFontSize = screenWidth / 1920
} else {
currentFontSize = screenHeight / 1040
}

document.documentElement.style.fontSize = currentFontSize + 'px'
}

(function (w) {
w.addEventListener('resize', setSize)
w.addEventListener('pageShow', setSize)
w.addEventListener('DOMContentLoaded', setSize)
})(window)
setSize()
阅读全文
electron打包桌面应用

官方文档

结构

1
2
3
4
5
my-electron-app/
├── package.json
├── main.js
├── preload.js
└── index.html
阅读全文
uni-app

接口请求发生错误,可能原因

安卓系统请求头部不会自动带上Content-Type,后台代码有校验

安卓系统6.0以上会提示需要获取手机权限,不允许授权时候应用会闪退问题解决方案:

manifest.json 文件中,app-plus.distribute.android 增加以下代码

1
2
3
4
5
6
7
8
"permissionExternalStorage" : {
"request" : "none",
"prompt" : "应用保存运行状态等信息,需要获取读写手机存储(系统提示为访问设备上的照片、媒体内容和文件)权限,请允许。"
},
"permissionPhoneState" : {
"request" : "none",
"prompt" : "为保证您正常、安全地使用,需要获取设备识别码(部分手机提示为获取手机号码)使用权限,请允许。"
}
阅读全文
更换主题颜色
  1. 把 css 文件放到服务器上,通过 XMLHttpRequest 请求文件,获取到文件内容之后替换颜色。
    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
    getFile(url: string) {
    return new Promise((resolve, reject) => {
    const client = new XMLHttpRequest();
    client.open("GET", url);
    client.responseType = "text";
    client.onreadystatechange = () => {
    if (client.readyState !== 4) {
    return;
    }
    if (client.status === 200) {
    const urlArr = client.responseURL.split("/");
    resolve({
    data: client.response,
    url: urlArr[urlArr.length - 1],
    });
    } else {
    reject(new Error(client.statusText));
    }
    };
    client.send();
    });
    }

    getIndexStyle() {
    this.getFile("//doc.mamaezhan.com/web/my_theme.css")
    .then(({data}: any) => {
    this.originalStyle = this.getStyleTemplate(data);
    this.writeNewStyle();
    });
    }
阅读全文
Vue + TypeScript

项目相关配置在哪里写?

由于采用vue-cli@3.x版本来初始化工程,所以没有了2.x版本对外暴露的webpack配置文件,所以如果相对项目进行一些配置,需要在项目根目录下新建vue.config.js.
比如需要修改项目启动的端口号,去掉打包后文件名的哈希值,如下:

1
2
3
4
5
6
7
module.exports = {
baseUrl: '/', // 默认为根目录下 '/'
devServer: {
port: 8989
},
filenameHashing: false
}

Vue.prototype 定义的全局变量无法使用

如果在main中定义了一个全局变量

1
2
import apiConfig from "@/apiConfig";
Vue.prototype.apiConfig = apiConfig;

但是在组件中无法使用该变量,需要在 .d.ts 文件中加入如下代码:

1
2
3
4
5
6
import Vue from "vue";
declare module "vue/types/vue" {
interface Vue {
apiConfig: any;
}
}

以上代码可在官方文档找到

阅读全文
Gitment评论

在根目录的 _config.yml 中添加下面代码

1
2
3
4
5
6
7
8
# 评论
comments:
gitment:
enable: true
owner: '' // github 的 ID 或用户名
repo: '' // 用于存储评论的 GitHub 仓库名称
client_id: '' // 注册 gitment 获得的 client_id
client_secret: '' // 注册 gitment 获得的 client_secret
阅读全文
Algolia