前端常用方法

2022-06-27 16:45:13 字數 2271 閱讀 9825

// 根據id去重,可改

private deweight(arr: any) }}

return arr;

}// 深拷貝

private deepclone(obj: any) ;

for (const key in obj) else }}

return result;

}

/**

* 時間獲取

* 使用例子:

*/ // 獲取時間

const now = new date(); // 當前日期

const nowdayofweek = now.getday(); // 今天本週的第幾天

const nowday = now.getdate(); // 當前日

const nowmonth = now.getmonth(); // 當前月

const nowyear = now.getfullyear(); // 當前年

const lastmonth = nowmonth - 1;

let startdate = '';

let enddate = '';

if (opttype === 1) else if (opttype === 2)

return ;

} private getmonthdays(nowyear: any, mymonth: any)

private formatdatefn(date: any)

if (myweekday < 10)

return (myyear + '-' + mymonth + '-' + myweekday);

} // 獲取當前的日期

private getdaytime()

//

區域性元件批量引入

const requirecomponent =require.context(

'./', //

元件所在目錄的相對路徑

true, //

是否查詢其子目錄

/\w+\.vue$/ //

匹配基礎元件檔名的正規表示式

)let comobj: any ={};

requirecomponent.keys().foreach((filename: any) =>)

//全域性元件批量引入(main.js引入)

const requirecomponent =require.context(

'./', //

元件所在目錄的相對路徑

false, //

是否查詢其子目錄

/base[a-z]\w+\.(vue|js)$/ //

匹配基礎元件檔名的正規表示式

)requirecomponent.keys().foreach(filename=>)

//

el-table 動態合併**

data 裡面定義

spanarr: ,

pos: 0,

contentspanarr: ,

position: 0,

customerarr: ,

customer: 0

//需要合併的行和列

test()

else

else

//判斷當前元素與上乙個元素是否相同(第2列)

if (this.tabledata2[index].year === this.tabledata2[index - 1].year && this.tabledata2[index].customername === this.tabledata2[index - 1].customername)

else

//判斷當前元素與上乙個元素是否相同(第3列)

if (this.tabledata2[index].customercode === this.tabledata2[index - 1].customercode && this.tabledata2[index].customername === this.tabledata2[index - 1].customername)

else}})

},//合併單元格

objectspanmethod2() ;

} else

if (columnindex === 1) ;

} else

if (columnindex === 2) ;

}},

前端常用方法

1 設定背景為固定,這樣拉動滾動條時背景不會變化 body 2 鏈結錨點,實現鏈結到頁面頂部 到頁面底部 功能 到頁面底部 到頁面頂部 3 游標設定 style cursor pointer pointer 手式 auto text 文字游標 crosshair 十字交叉 move 移動游標 wai...

前端開發常用方法

淺拷貝和深拷貝 let arr arr 淺拷貝 object.assign arr 淺拷貝 clonedeep arr 深拷貝 json parse json stringify arr 深拷貝 不能拷貝 constructor 方法 陣列去重 uniquekey arr,key let resul...

前端解決跨域問題的常用方法

首先,跨域是什麼?只要協議 網域名稱 埠有任何乙個不同,都被當作是不同的域。為什麼三者任何乙個不同就會產生跨域呢,想想也很容易知道,要是很隨便引用什麼外部檔案,不同標籤下的頁面引用類似的彼此的檔案,瀏覽器很容易懵逼的,保障不了安全問題,但在安全限制的同時也給注入iframe或是ajax請求上帶來了不...