此問題出現(xiàn)在我閱讀別人的源碼時(shí),對于此處傳值有些不解,不知道是不是vue的一個(gè)特性,問題如下:在全局注冊了一個(gè)方法export function parseTime(time, cFormat) { console.log(time) if (arguments.length === 0) { return null } if ((time + '').length === 10) { time = +time * 1000 } const format = cFormat || '{y}-{m}-nhkv1sx5v02o {h}:{i}:{s}' let date if (typeof time === 'object') { date = time } else { date = new Date(parseInt(time)) } const formatObj = { y: date.getFullYear(), m: date.getMonth() + 1, d: date.getDate(), h: date.getHours(), i: date.getMinutes(), s: date.getSeconds(), a: date.getDay() } const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => { let value = formatObj[key] if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1] if (result.length > 0 && value < 10) { value = '0' + value } return value || 0 }) return time_str}這時(shí)候在組件內(nèi)進(jìn)行這樣的調(diào)用,直接傳遞了我認(rèn)為是該方法的第二個(gè)參數(shù)--時(shí)間格式,那么time參數(shù)是怎么傳遞的呢?調(diào)用如下: <el-table-column width="180px" align="center" label="Date"> <template slot-scope="scope"> <span>{{scope.row.timestamp | parseTime('{y}-{m}-nhkv1sx5v02o {h}:{i}')}}</span> </template> </el-table-column>主要是不明白為什么沒有傳遞parseTime()方法的time參數(shù)直接傳遞了cFormat參數(shù),是什么原理呢?
js中方法參數(shù)傳值的問題
慕仙森
2019-03-14 14:15:57