-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alexmenshikov
committed
Aug 18, 2024
1 parent
d7a9348
commit 2920da1
Showing
1 changed file
with
34 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,51 @@ | ||
import { defineComponent } from 'vue' | ||
import { defineComponent, ref, watch } from 'vue' | ||
|
||
export default defineComponent({ | ||
name: 'CalculatorApp', | ||
|
||
setup() {}, | ||
setup() { | ||
const firstNumber = ref(0); | ||
const secondNumber = ref(0); | ||
const picked = ref('sum'); | ||
const result = ref(0); | ||
|
||
watch([firstNumber, secondNumber, picked], () => { | ||
switch(picked.value) { | ||
case 'sum': | ||
return result.value = firstNumber.value + secondNumber.value | ||
case 'subtract': | ||
return result.value = firstNumber.value - secondNumber.value | ||
case 'multiply': | ||
return result.value = firstNumber.value * secondNumber.value | ||
case 'divide': | ||
return result.value = firstNumber.value / secondNumber.value | ||
} | ||
}); | ||
|
||
return { | ||
firstNumber, | ||
secondNumber, | ||
picked, | ||
result, | ||
} | ||
}, | ||
|
||
template: ` | ||
<div class="calculator"> | ||
<input type="number" aria-label="First operand" /> | ||
<input type="number" aria-label="First operand" v-model="firstNumber" /> | ||
<div class="calculator__operators"> | ||
<label><input type="radio" name="operator" value="sum"/>➕</label> | ||
<label><input type="radio" name="operator" value="subtract"/>➖</label> | ||
<label><input type="radio" name="operator" value="multiply"/>✖</label> | ||
<label><input type="radio" name="operator" value="divide"/>➗</label> | ||
<label><input type="radio" name="operator" value="sum" v-model="picked" />➕</label> | ||
<label><input type="radio" name="operator" value="subtract" v-model="picked" />➖</label> | ||
<label><input type="radio" name="operator" value="multiply" v-model="picked" />✖</label> | ||
<label><input type="radio" name="operator" value="divide" v-model="picked" />➗</label> | ||
</div> | ||
<input type="number" aria-label="Second operand" /> | ||
<input type="number" aria-label="Second operand" v-model="secondNumber" /> | ||
<div>=</div> | ||
<output>0</output> | ||
<output>{{ result }}</output> | ||
</div> | ||
`, | ||
}) |