Vue实现双向绑定的原理就是利用了Object.defineProperty()这个方法从新定义了对象获取属性值(get)和设置属性值(set)的操做来实现的。vue
由于一个组件是能够共享的,但他们的data是私有的,因此每一个组件都要return一个新的对象,返回一个惟一的对象,不要和其余组件共用一个对象webpack
var a = [1,2,3]
var b = [4,5,6]
var c = a.concat(b) //c = [1,2,3,4,5,6]
复制代码
var a = [1,2,3]
var b = [4,5,6]
var c = a.push.apply(a,b)
复制代码
let arr1 = [1,2,3]
let arr2 = [2,3,4]
let arr = arr1.concat(arr2) //合并数组
let arrNew = new Set(arr) //经过set集合去重
Array.from(arrNew) //将set集合转化为数组
复制代码
.parent {
position: relative;
}
.child {
position: absolute;
left: 50%;
rigth: 50%;
transfrom: translate(-50%,-50%)
}
复制代码
.parent {
display: flex;
justify-content: center; //水平居中
align-items: center; //垂直居中
}
复制代码
call的实现思路ios
//call的实现思路
Function.prototype.myCall = function (context){
if (typeof this !== 'function') {
throw new TypeError('Error')
}
var context = context || window
//给context添加一个属性
context.fn = this
//经过参数伪数组将context后面的参数取出来
var args = [...arguments].slice(1)
var result = context.fn(...args)
//删除 fn
delete context.fn
return result
}
复制代码
apply的实现思路web
//apply的实现思路
Function.prototype.myApply = function (context) {
if (typeof this !== 'function') {
throw new TypeError('Error')
}
var context = context || window
//为context添加一个属性
context.fn = this
var result
//判断是否存在第二个参数
//若是存在就将第二个参数也展开
if(arguments[1]) {
result = context.fn(...arguments[1])
} else {
result = context.fn()
}
delete context.fn
return result
}
复制代码
bind的实现思路:bind返回了一个函数,对于函数来讲有两种调用方式,一种是直接的调用,一种是经过new的方式面试
Function.prototype.myBind = function (context) {
if (typeof this !== 'function') {
throw new TypeError('Error')
}
const _this = this
const args = [...arguments].slice(1)
//返回一个函数
return function F () {
if (this instanceof F) {
return new _this(...args, ...arguments)
}
return _this.apply(context,args.concat(...arguments))
}
}
复制代码
vue是虚拟DOM操做的,JQuery.ajax和都须要操做DOM,官方不推荐,并且axios自己就能够解决回调地狱的问题ajax
loaclStorage声明周期是永久的,存放数据通常为5MB;sessionStorage仅在当前会话下有效,关闭页面或者浏览器后被清除,存放数据大小通常为5MB;cookie具备极高的扩展性和可用性,存放数据大小为4k左右,有个数限制,通常不能超过20个。localStorage、sessionStorage、Cookie共同点:都是保存在浏览器端,且同源的。vue-router
在调用new的过程当中会发生四件事:vuex
function createNew() {
let obj = {}
let Sunday = [].shift.call(arguments)
obj.__proto__ = Sunday.prototype
let result = Sunday.apply(obj,arguments)
return result instanceof Object ? result : obj
}
复制代码
vue-router路由提供了两种路由模式:hash模式和history模式。axios
组件通讯通常分为三种:数组