Compare commits

..

3 Commits
master ... main

@ -6,7 +6,9 @@
<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>
@ -29,6 +31,8 @@ const operators = [
{ operator: '%' },
];
const appendNumber = (number) => {
if (displayValue.value === '0' || displayValue.value === '表达式错误') {
displayValue.value = number;
@ -47,6 +51,16 @@ 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 = () => {
@ -55,6 +69,12 @@ 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>

@ -0,0 +1,7 @@
1. 使用Hbuilder打开项目目录在该目录打开Hbuilder内置终端输入yarn命令
2. 再输入yarn dev命令启动服务器
3. 打开内置终端生成的网络地址
Loading…
Cancel
Save