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
組件通訊通常分爲三種:數組