微信小程序:计算器项目

本文档介绍了如何制作微信小程序计算器,涉及index.is、index.json、index.wxml和index.wxss文件的编写,通过这些步骤最终完成计算器小程序的制作。源码可在CSDN文库下载。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

对index.is文件进行编写

// pages/index/index.js
const calc = require('../../utils/calc.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    num: '0',
    op: ''
  },

  result: null,
  isClear: false,

  // 数字按钮事件处理函数
  numBtn: function(e) {
    var num = e.target.dataset.val
    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 = calc.add(this.result, num)
    } else if (op 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值