0%

参考文档

一、前置条件

uni-forms 需要绑定 model 属性,值为表单的 key/value 组成的对象。uni-form-item 需要设置 name 属性为当前字段名,字段为 String|Array 类型。

1
2
3
4
5
6
7
8
<uni-forms :modelValue="formData">
<uni-forms-item label="姓名" name="name">
<uni-easyinput type="text" v-model="formData.name" placeholder="请输入姓名" />
</uni-forms-item>
<uni-forms-item required :name="['data','hobby']" label="兴趣爱好">
<uni-data-checkbox multiple v-model="formData.data.hobby" :localdata="hobby"/>
</uni-forms-item>
</uni-forms>
阅读全文 »

ES6 Module 和 CommonJS 模块的区别:

  • CommonJS 模块是同步加载的,而 ES6 模块是异步加载的。
  • CommonJS 模块是运行时加载,而 ES6 模块是编译时加载。
  • CommonJS 模块输出的是一个值的拷贝,而 ES6 模块输出的是一个值的引用。

require 用于读取并执行 js 文件,并返回该模块的 exports 对象,若无指定模块,会报错。Node 使用 CommonJS 模块规范,CommonJS 规范加载模块是同步的,只有加载完成,才能执行后续操作。

import 用于引入外部模块,其他脚本等的函数,对象或者基本类型。import 属于 ES6 的命令,它和 require 不一样,它会生成外部模块的引用而不是加载模块,等到真正使用到该模块的时候才会去加载模块中的值。

阅读全文 »

在团队协作中,为避免低级 Bug、产出风格统一的代码,会预先制定编码规范。使用 Lint 工具和代码风格检测工具,则可以辅助编码规范执行,有效控制代码质量。

阅读全文 »

AJAX

(一)AJAX 概述

AJAX(Asynchronous JavaScript And XML,异步的 JavaScript 和 XML),是一种实现无页面刷新获取服务器数据的混合技术。它能够使浏览器在不刷新页面的情况下获取服务器响应,这将大大提升互联网用户的使用体验,同时,由于 AJAX 请求获取的是数据而不是 HTML 文档,因此它也节省了网络带宽,让互联网用户的网络冲浪体验变得更加顺畅。

阅读全文 »

(一)数组常见需求

检验数组

不能使用 typeof 方法检验一个变量是否为数组,因为它的检测结果只有 undefinedobjectfunctionbooleanstringnumberbigintsymbol

1
2
var arr = ['a', 'b', 'c'];
console.log(typeof(arr)); //"object"
阅读全文 »

1. 判断是否为对象

1
2
Object.prototype.toString.call({}) === '[object Object]'
Object.prototype.toString.call([]) === '[object Array]'
阅读全文 »

0. 获取 dom 节点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
document.getElementById('id')
// 通过 ID 获取,上下文只能是 document,返回值只获取到一个元素,没有找到返回 null

document.getElementsByName('name')
// 通过 name 属性获取,上下文只能是 document,返回值是一个类数组,没有找到返回空数组

document.getElementByTagName('p')
var oDiv = document.getElementById('divId')
oDiv.getElementsByTagName('p')
// 通过标签获取,上下文可以是 document 和 dom 节点,返回值是一个类数组,没有找到返回空数组

document.getElementByClassName('class')
// 通过类名获取,上下文可以是 document 和 dom 节点,返回值是一个类数组,没有找到返回空数组,ie8 以下不兼容

document.querySelector('div.class')
// 通过选择器获取,上下文可以是 document 和 dom 节点,返回值只获取到一个元素

document.querySelectorAll('div.class')
// 通过选择器获取,上下文可以是 document 和 dom 节点,返回值是一个类数组

document.documentElement // 获取 html
document.body // 获取 body
document.body.contentEditable="true" // 文本可编辑
document.querySelector('video').playbackRate = 3; // 视频播放速度
阅读全文 »

Math is a built-in object that has properties and methods for mathematical constants and functions. It’s not a function object.

Math works with the Number type. It doesn’t work with BigInt.

阅读全文 »

一、创建对象的方式

① 工厂模式

1
2
3
4
5
6
7
8
9
function createPerson(name) {
var o = new Object();
o.name = name;
o.getName = function () {
console.log(this.name);
};
return o;
}
var person1 = createPerson('kevin');
阅读全文 »

深浅拷贝

浅拷贝:只考虑对象类型。

1
2
3
4
5
6
7
8
9
10
11
function shallowCopy(obj) {
if (typeof obj !== 'object') return
let newObj = obj instanceof Array ? [] : {}
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
newObj[key] = obj[key]
}
}
return newObj
}

阅读全文 »