您好,登錄后才能下訂單哦!
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返回的是數(shù)值,先進行-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中 數(shù)字相加為字串轉化為數(shù)值的例子就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。