vue中 數字相加為字串轉化為數值的例子
更新時間:2019年11月07日 08:36:30 作者:一抹胭脂冷
今天小編就為大家分享一篇vue中 數字相加為字串轉化為數值的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
month傳入為3時,下面代碼輸出為31
if(data1.attr === 'last_month') { if(month === 1) { year = year - 1 } else { month = this.trans_Date(month - 1) } } else if(data1.attr === 'next_month') { if(month === 12) { year = year + 1 month = this.trans_Date(1) } else { month=this.trans_Date(month +1); console.log("month", month) } } else { month=this.trans_Date(month) } trans_Date(data) { if (data < 10) { return '0' + data } else { return data } }
控制臺輸出為
想要month+1返回的是數值,先進行-0在進行+1。
if(data1.attr === 'last_month') { if(month === 1) { year = year - 1 } else { month = this.trans_Date(month - 1) } } else if(data1.attr === 'next_month') { if(month === 12) { year = year + 1 month = this.trans_Date(1) } else { month=this.trans_Date(month-0 +1); console.log("month", month) } } else { month=this.trans_Date(month) }
控制臺輸出為
以上這篇vue中 數字相加為字串轉化為數值的例子就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Vue動態(tài)擴展表頭的表格及數據方式(數組嵌套對象)
這篇文章主要介紹了Vue動態(tài)擴展表頭的表格及數據方式(數組嵌套對象),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-03-03如何優(yōu)雅的在一臺vps(云主機)上面部署vue+mongodb+express項目
這篇文章主要介紹了如何優(yōu)雅的在一臺vps(云主機)上面部署vue+mongodb+express項目,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-01-01