Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. new Vue({
  2. el: '#app',
  3. data: {
  4. usd: '',
  5. canadianDollar: '',
  6. europeanPound: '',
  7. europeanEuro: ''
  8. },
  9.  
  10. // Watch methods
  11. watch: {
  12. usd: function() {
  13. this.convertCurrency()
  14. }
  15. },
  16.  
  17. // Logic Methods
  18. methods: {
  19. convertCurrency: _.debounce(function() {
  20. var app = this;
  21. if (app.usd.length !== 0) {
  22.  
  23. // Show that the things are loading in.
  24. app.canadianDollar = 'Searching...'
  25. app.europeanPound = 'Searching...'
  26. app.europeanEuro = 'Searching...'
  27. console.log(app.usd)
  28. axios.get("http://api.fixer.io/latest?base=USD&" + app.usd)
  29. .then(function(response) {
  30. app.canadianDollar = response.data.CAD
  31. app.europeanPound = response.data.GBP
  32. app.europeanEuro = response.data.EUR
  33. })
  34. .catch(function(error){
  35. app.canadianDollar = "ERROR"
  36. app.europeanPound = "ERROR"
  37. app.europeanEuro = "ERROR"
  38. })
  39. }
  40. }, 500)
  41. }
  42. })
  43.  
  44. <!DOCTYPE html>
  45. <html>
  46. <head>
  47. <title>Welcome to Vue</title>
  48. <script src="https://unpkg.com/vue/dist/vue.js"></script>
  49. </head>
  50. <body>
  51. <div id="app">
  52. <input type="text" name="" value="" v-model="usd">
  53. <ul>
  54. <li>Canadian Dollar: {{canadianDollar}}</li>
  55. <li>European Pound: {{europeanPound}}</li>
  56. <li>European Euro: {{europeanEuro}}</li>
  57. </ul>
  58. </div>
  59. <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  60. <script src="https://cdn.jsdelivr.net/lodash/4.17.4/lodash.min.js" charset="utf-8"></script>
  61. <script src="index.js" charset="utf-8"></script>
  62. </body>
  63. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement