Skip to content

Instantly share code, notes, and snippets.

@LukeTully
Created March 22, 2017 23:25
Show Gist options
  • Save LukeTully/544c2c553d2334d6585afdb292b1cd9e to your computer and use it in GitHub Desktop.
Save LukeTully/544c2c553d2334d6585afdb292b1cd9e to your computer and use it in GitHub Desktop.
Basic Vue-based loan calculator
<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>
@LukeTully
Copy link
Author

Here's an example of this working with slightly altered code.
https://jsfiddle.net/baconchez/1pm7qez9/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment