|
|
|
@ -6,9 +6,7 @@
|
|
|
|
|
<OperatorButton v-for="op in operators" :key="op.operator" :operator="op.operator" @click="appendOperator(op.operator)" />
|
|
|
|
|
<button @click="appendDecimal('.')">.</button>
|
|
|
|
|
<button @click="calculate">=</button>
|
|
|
|
|
<button @click="deleteLastChar">del</button>
|
|
|
|
|
<button class="ac-button" @click="clearDisplay">AC</button>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
@ -31,8 +29,6 @@ const operators = [
|
|
|
|
|
{ operator: '%' },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const appendNumber = (number) => {
|
|
|
|
|
if (displayValue.value === '0' || displayValue.value === '表达式错误') {
|
|
|
|
|
displayValue.value = number;
|
|
|
|
@ -51,16 +47,6 @@ const appendOperator = (op) => {
|
|
|
|
|
|
|
|
|
|
const calculate = () => {
|
|
|
|
|
displayValue.value = eval(displayValue.value);
|
|
|
|
|
try {
|
|
|
|
|
const result = Function('"use strict"; return (' + displayValue.value + ')')();
|
|
|
|
|
if (!isFinite(result)) {
|
|
|
|
|
displayValue.value = '错误';
|
|
|
|
|
} else {
|
|
|
|
|
displayValue.value = result;
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
displayValue.value = '错误';
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const clearDisplay = () => {
|
|
|
|
@ -69,12 +55,6 @@ const clearDisplay = () => {
|
|
|
|
|
secondNumber.value = null;
|
|
|
|
|
operator.value = null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const deleteLastChar = () => {
|
|
|
|
|
if (displayValue.value.length > 0) {
|
|
|
|
|
displayValue.value = displayValue.value.slice(0, -1); // 删除最后一个字符
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|