A Pen by Diego Lipinski de Castro on CodePen.
Created
August 17, 2017 22:27
-
-
Save diego-lipinski-de-castro/7053ddd15ebc54909cbded84bfb7392b to your computer and use it in GitHub Desktop.
Binário
This file contains 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#app | |
.columns | |
.column.is-offset-one-quarter | |
template(v-for="type in typeConversions") | |
.field | |
label.label {{ type.name }} | |
.control | |
input.input(v-model="type.result" type="text" disabled) | |
hr | |
.field | |
.control | |
input.input(v-model="input" type="text" placeholder="Input" v-bind:disabled="selectedType.length <= 0") | |
.select | |
select(v-model="selectedType") | |
option(value="nulled" disabled) Select input base type | |
template(v-for="type in typeConversions") | |
option(:value="type.value") {{ type.name }} | |
hr | |
button.button.is-primary(@click="calculate()") Calculate | |
button.button.is-primary(@click="reset()" style="float: right") Reset |
This file contains 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({ | |
el: "#app", | |
data() { | |
return { | |
first: "", | |
last: "", | |
input: "", | |
typeConversions: [ | |
{ value: "decimal", base: 10, name: "Decimal", result: "" }, | |
{ value: "hexadecimal", base: 16, name: "Hexadecimal", result: "" }, | |
{ value: "octadecimal", base: 8, name: "Octadecimal", result: "" }, | |
{ value: "binario", base: 2, name: "Binário", result: "" } | |
], | |
selectedType: "" | |
}; | |
}, | |
created() { | |
self = this; | |
}, | |
methods: { | |
calculate: () => { | |
let typeItem = $.grep(self.typeConversions, type => { | |
return type.value == self.selectedType; | |
}); | |
let newDecimal = self.toDecimal(self.input, typeItem[0].base); | |
self.typeConversions.forEach(item => { | |
item.result = self.converion(newDecimal, item.base); | |
}); | |
}, | |
toDecimal: (value, base) => { | |
return parseInt(value, base); | |
}, | |
converion: (value, newBase) => { | |
return self.toDecimal(value).toString(newBase); | |
}, | |
reset: () => { | |
self.input = ""; | |
self.selectedType = ""; | |
self.typeConversions.forEach(item => { | |
item.result = ""; | |
}); | |
} | |
} | |
}); |
This file contains 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/jquery/3.2.1/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.min.js"></script> |
This file contains 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
html, body | |
height 100% | |
body | |
display flex | |
align-items center | |
justify-content center |
This file contains 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
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.4.2/css/bulma.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment