-
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.
Merge pull request #6 from luquii2/master
карта
- Loading branch information
Showing
3 changed files
with
44 additions
and
23 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
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
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,52 @@ | ||
import { defineComponent } from 'vue' | ||
import { defineComponent, ref, computed } from 'vue' | ||
|
||
export default defineComponent({ | ||
name: 'CalculatorApp', | ||
|
||
setup() {}, | ||
setup() { | ||
|
||
const calc = ref({ | ||
firstOperand: 0, | ||
secondOperand: 0, | ||
operator: null, | ||
}) | ||
|
||
const output = computed(() => { | ||
switch (calc.value.operator) { | ||
case "sum": | ||
return calc.value.firstOperand + calc.value.secondOperand; | ||
case "subtract": | ||
return calc.value.firstOperand - calc.value.secondOperand; | ||
case "multiply": | ||
return calc.value.firstOperand * calc.value.secondOperand; | ||
case "divide": | ||
return calc.value.firstOperand / calc.value.secondOperand; | ||
default: | ||
return 0 | ||
} | ||
}) | ||
|
||
return { | ||
calc, | ||
output, | ||
} | ||
}, | ||
|
||
template: ` | ||
<div class="calculator"> | ||
<input type="number" aria-label="First operand" /> | ||
<input v-model="calc.firstOperand" type="number" aria-label="First operand" /> | ||
<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 v-model="calc.operator" type="radio" name="operator" value="sum"/>➕</label> | ||
<label><input v-model="calc.operator" type="radio" name="operator" value="subtract"/>➖</label> | ||
<label><input v-model="calc.operator" type="radio" name="operator" value="multiply"/>✖</label> | ||
<label><input v-model="calc.operator" type="radio" name="operator" value="divide"/>➗</label> | ||
</div> | ||
<input type="number" aria-label="Second operand" /> | ||
<input v-model="calc.secondOperand" type="number" aria-label="Second operand" /> | ||
<div>=</div> | ||
<output>0</output> | ||
<output>{{ output }}</output> | ||
</div> | ||
`, | ||
}) |