Created
March 22, 2017 23:25
-
-
Save LukeTully/544c2c553d2334d6585afdb292b1cd9e to your computer and use it in GitHub Desktop.
Basic Vue-based loan calculator
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
<template> | |
<div id="app-container"> | |
<form> | |
<label for="principal">Principal</label> | |
<input type="number" name="principal" v-model="principal" /> | |
<label for="rate">Rate</label> | |
<input type="text" name="rate" v-model="rate" /> | |
</form> | |
<p> | |
Total Amount: {{totalAmount}} | |
</p> | |
<p> | |
Payments: | |
</p> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: 'app', | |
data () { | |
rate: 0.05, | |
principal: 20000, | |
time: 5, | |
increments: 12 | |
}, | |
computed: { | |
totalAmount: function() { | |
// Calculate compound interest using the formula: P (1 + r/n) (nt) - P | |
return Math.floor(this.principal * Math.pow((1 + this.rate / this.increments), this.increments * this.time)); | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's an example of this working with slightly altered code.
https://jsfiddle.net/baconchez/1pm7qez9/