开发小技巧,持续收集中...

479 阅读1分钟

1.判断是否是移动端

const isMobile = () => 'ontouchstart' in window

2.通过正则限制输入框小数点后2位

<el-input v-model.number="value" @input="oninput" ></el-input>
oninput(e){
    e = (e.match(/^\d*(\.?\d{0,2})/g)[0]) || null;
    this.value = e
}

3.使用pre标签实现定义预格式化的文本的坑

<pre>
此例演示如何使用 pre 标签
对空行和 空格
进行控制
</pre>

内容溢出,需要设置 white-space:pre-wrap,保留空白符序列,并正常地进行换行.

4.el-input中绑定v-model.number产生的坑

校验输入框最大限制位数的时候,超过一定位数后变成科学计数法。

避坑,尽量不要使用v-model.number。

5.判断H5内嵌app的环境 var userAgent = navigator.userAgent.toLowerCase();//获取UA信息 if(userAgent.indexOf("isApp") != -1){//判断ua中是否含有和app端约定好的标识isApp alert('包含'); }