溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

vue中 數(shù)字相加為字串轉化為數(shù)值的例子

發(fā)布時間:2020-10-08 17:08:54 來源:腳本之家 閱讀:141 作者:一抹胭脂冷 欄目:web開發(fā)

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ù)值的例子

以上這篇vue中 數(shù)字相加為字串轉化為數(shù)值的例子就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。

AI