Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize calculator by WeChat Mini Programs

Shulou Source: shulou.com Published: 2022-06-01 00:41:15 09月21日 Update

This article introduces the relevant knowledge of "how to realize the calculator by WeChat Mini Programs". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The effect is as follows:

Index.wxml

{{num}} {{op}} c DEL% / 7 8 9 x 4 56-1 2 3 + 0. =

Index.css

Page {display: flex; flex-direction: column; height: 100%;}. Content {flex: 1; background-color: # f3f6fe; position: relative;}. Content .num {position: absolute; font-size: 27pt; bottom: 5vh; right: 3vW;} .content .operotor {font-size: 15pt; position: absolute; bottom: 1vh; right: 3vW;} .entry {flex: 1; font-size: 17pt; border-top: 1rpx solid # ccc } .entry .item {flex: 1; padding: 30rpx 0; text-align: center; flex-basis: 25%; border-left: 1rpx solid # ccc; border-bottom: 1rpx solid # ccc;}. Entry > view {display: flex;}. Entry > view .tow {flex: 2;} .entry > view .one {flex: 1;}

Index.js

Page ({data: {num: ", / / store digits op:" / / Storage operator}, result: null, isClear: false NumBtn: function (e) {var num = e.target.dataset.val / / console.log (num) get the value of data-val console.log (this.isClear) if (this.data.num = "0" | | this.isClear) {this.setData ({num: num}) this.isClear = false} else { This.setData ({num: this.data.num + num})}} OpBtn: function (e) {var op = this.data.op var num = Number (this.data.num) this.setData ({op: e.target.dataset.val}) if (this.isClear) {return} this.isClear = true if (this.result = = null) {this.result = num return } if (op = = "+") {this.result = this.result + num} else if (op = "-") {this.result = this.result-num} else if (op = = "*") {this.result = this.result * num} else if (op = = "/") {this.result = this.result / num} else if (op = = "%") {this.result = this.result% num} this.setData ({num: this.result})} DotBtn: function () {if (this.isClear) {this.setData ({num: "0."}) this.isClear = false return} if (this.data.num.indexOf (".") > = 0) {return} this.setData ({num: this.data.num + "."})} DelBtn: function () {var num = this.data.num.substr (0, this.data.num.length-1) this.setData ({num: num = = "?" 0 ": num})}, resetBtn: function () {this.result = null this.isClear = false this.setData ({num:" 0 ") Op: ""}) how does WeChat Mini Programs realize the Calculator? "that's it. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Programs calculators content more knowledge storage practicality learning and then dilemmas realities situations effects numbers articles cases editing websites industries processes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB vpn macOS Apple OPPO Reno