A Pen by Edward Lance Lorilla on CodePen.
Created
October 12, 2019 14:52
-
-
Save edwardlorilla/db2c17fd6ea11cb6a5ec49fe11659159 to your computer and use it in GitHub Desktop.
multiline Seconds to Hours:Minutes:Seconds vuejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="app"> | |
<textarea name="second" id="second" cols="30" rows="10" v-model="second"></textarea> | |
<textarea v-model="secondToHMS" name="hms" id="hms" cols="30" rows="10"></textarea> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Vue({ | |
data(){ | |
return{ | |
second: '', | |
} | |
}, | |
computed:{ | |
secondToHMS(){ | |
var vm = this,text = this.second | |
var lines = text.split('\n'); | |
text = text.replace(/\r\n/g, '\n'); | |
var ret = ''; | |
var hms = [] | |
for (var i = 0; i < lines.length; i++) { | |
var line = lines[i]; | |
if (/(\d+)/.test(line)) { | |
var seconds = line; | |
var hours = Math.floor(seconds / 3600); | |
var minutes = Math.floor((seconds - hours*3600) / 60); | |
var seconds = seconds % 60; | |
ret += hours + ':' + minutes + ':' + seconds; | |
} | |
else { | |
ret += line; | |
} | |
ret += '\n'; | |
} | |
return ret | |
} | |
} | |
}).$mount('#app') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment