Advertisement
Pripovedac

VueCalculator

Aug 11th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var app = new Vue({
  3.   el: '#app-1',
  4.   data: {
  5.     heading: 'Daretron vol. 2',
  6.     selected: 'Operacija',
  7.     options: [{
  8.       label: 'Operacija'
  9.     },
  10.     {
  11.       label: '+',
  12.       op: (a, b) => a + b
  13.     }, {
  14.       label: '-',
  15.       op: (a, b) => a - b
  16.     }, {
  17.       label: '*',
  18.       op: (a, b) => a * b
  19.     }, {
  20.       label: '/',
  21.       op: (a, b) => a / b
  22.     }],
  23.     firstOperand: "",
  24.     secondOperand: "",
  25.     result: "",
  26.   },
  27.   methods: {
  28.     operation: function()  {
  29.       var selectedOperation = this.options.find(item => item.label == this.selected)
  30.       this.result = selectedOperation.op(parseFloat(this.firstOperand), parseFloat(this.secondOperand))
  31.       this.firstOperand = ""
  32.       this.secondOperand = ""
  33.       this.selected = "Operacija"
  34.     }
  35.   }
  36. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement