Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize calculator by WeChat Mini Programs

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report