前端实现计算器。。应该不难。
第一步:先建个项目:
项目结构如下:

注意:这个vue.js懂的都懂,官网下载或者一些编译器都自带的,这个不放代码了。
不多说,其他直接上代码。
第二步:html代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="calculator.css">
</head>
<body>
<div id="app">
<table id="cal">
<tr>
<td id="output" colspan="4">{
{ output }}</td>
</tr>
<tr v-for="row in keys">
<td v-if="key.value===0" :colspan="2" v-for="key in row" @click="keyClick(key)" :class="{
'bg-yellow': key.type === 'op', 'bg-gray': key.type === 'num'}">
{
{ key.label }}</td>
<td v-if="key.value!=0" v-for="key in row" @click="keyClick(key)" :class="{
'bg-yellow': key.type === 'op', 'bg-gray': key.type === 'num'}">
{
{ key.label }}</td>
</tr>
</table>
</div>
<script src="vue.js"></script>
<script src="calculator.js"></script>
</body>
</html>
第三步:CSS代码:
.bg-yellow {
background-color: #FF9C34 !important;
}
.bg-gray {
background-color: #62645D !important;
}
#cal {
margin: unset;
}
#cal #output {
background-color