首页 > 编程语言 >微信小程序开发周记(11.20-11.26)

微信小程序开发周记(11.20-11.26)

时间:2023-11-26 11:55:22浏览次数:36  
标签:count 重置 微信 周记 程序开发 detail value data 输入

实现1:下拉生成颜色

可以不断显示随机颜色。

image

下拉刷新可以重置颜色列表,上拉触底可以延申显示内容。

wxml:

<!--pages/getc/getc.wxml-->
<button type="primary" bind:tap="navifunc">后退</button>

<view class="num-item" wx:for="{{colorList}}" wx:key="index" style="background-color: {{item}};" >{{item}}</view>

这里通过 style 来设置背景颜色。可能存在在 wxss 中的写法。

js 部分代码:

	getcolor() {
      const numColors = 10;
      const generatedColors = [];

      for(let i=0; i<numColors; i++) {
        const red = Math.floor(Math.random() * 256);
        const green = Math.floor(Math.random() * 256);
        const blue = Math.floor(Math.random() * 256);
        const alpha = Math.floor(Math.random() * 256);

        const rgbaColor = `rgba(${red}, ${green}, ${blue}, ${alpha})`;
        generatedColors.push(rgbaColor);
      }

      this.setData({
        colorList: [...this.data.colorList, ...generatedColors]
      })
    },
    onPullDownRefresh() {
      this.setData({
        colorList: []
      })
      this.getcolor()
    },
    onReachBottom() {
        this.getcolor()
    },

实现2:计数器

输入自增步数,增加 count 。

image

wxml:

<!--pages/test/test.wxml-->
<button class="but" type="primary" bind:tap="tapfunction">增加count</button>


<block wx:if="{{isnumber}}">
  <view>总计的次数为{{count}}</view>
</block>
<block wx:else>
  <view>输入不是数字!</view>
  <button bind:tap="resetCount" size="mini" type="warn">重置</button>
</block>

<view>在此框内输入数字:</view>
<input value = "{{msg}}" bindinput="inputHandler"/>

js 部分代码:

    inputHandler(e) {
      this.setData({
        msg: e.detail.value,
        countInfo: Number(e.detail.value)
      })
      this.data.isnumber = !isNaN(Number(e.detail.value))
    },
            tapfunction(e) {
      this.setData({
        count: this.data.count + this.data.countInfo
      })
    },

但是似乎 wx:if 的判断灵敏度不高,在我输入非数字信息的时候并没有显示重置。

标签:count,重置,微信,周记,程序开发,detail,value,data,输入
From: https://www.cnblogs.com/imb514/p/17856687.html

相关文章

  • 微信小程序文件预览和下载-文件系统
    文件预览和下载在下载之前,我们得先调用接口获取文件下载的url然后通过wx.downloadFile将下载文件资源到本地wx.downloadFile({url:res.data.url,success:function(res){console.log('数据',res);}})tempFilePath就是临时临时文件路径。通过wx.openD......
  • 基于微信小程序的酒店管理系统设计与实现(源码+lw+部署文档+讲解等)
    (文章目录)详细视频演示请联系我获取更详细的演示视频具体实现截图[外链图片转存中...(img-Lkna8qpn-1700727246356)]技术栈后端框架SpringBootSpringBoot内置了Tomcat、Jetty和Undertow等服务器,这意味着你可以直接使用它们而不需要额外的安装和配置。SpringBoot的一......
  • 微信小程序 文字换行设置
    在wxml中的样式为block时,通过设置包裹文字的view的样式可达到换行,设置的属性为:word-break: break-word; 例:wxml和wxss<viewclass="text-format">超出的文字,超出的文字,超出的文字,超出的文字,超出的文字,超出的文字,<view>.text-form{word-break:break-word;......
  • 微信小程序--页面间传递数据的方式
    一、设置为全局变量,在另一个页面再获取这个变量 二、通过wx.navigateTo()的url传值 三、通过wx.navigateTo()的success建立一条数据通道传递数据的页面data:{data1:"第一个页面的值"},//在wxml页面设置一个按钮,并绑定事件dddddd:function(){va......
  • 用企业微信测试的坑........
    企业微信的授权登录流程讲解在这里这里使用微信开发者工具进行获取code的时候会提示错误信息,反正就是无法获取到,无法进行调试,就很烦这个东西后来才知道得在我这个图是网上冲浪顺的哈哈企业微信web开发者调试工具在我的企业找1.微工作台2.开启开发者工具,并点击web开发工具。......
  • uniapp-微信小程序绑定动态样式 :style 避坑
    在uniapp中绑定动态样式:style="object"使用此种方法,在H5页面中并不会出现任何问题而在微信小程序中,此种方式就会被编译成 style="[object,object]"从而导致样式无法生效解决方法:    使用:style="[object]"此种方式即可......
  • 2023.11.20-2023.11.26 周记
    11.20星期一升旗仪式时间改到上午大课间了,前一节还正好是体育,之前太冷现在太热,真服了。与其说升旗仪式,到不如说是颁奖仪式。七年级年级前十:李泊璇、陈墨杋、黄耀民、周敬轩、牛文昊、张轩豪、秦子祺、时欣翔、徐颢扬、宋之萱。八年级年级前十:何家鼎、李承恩、朱鑫、陈亦飞、张......
  • 微信小程序隐藏导航栏首页按钮
    隐藏“返回首页”按钮1、微信7.0.7版本起,当用户打开的小程序最底层页面是非首页时,默认展示“返回首页”按钮,开发者可在页面onShow中调用hideHomeButton进行隐藏。asynconShow(){uni.hideHomeButton()},2、uniapp通过pages.json隐藏返回首页”按钮{......
  • 获取微信版本、手机操作系统、手机类型
    效果图letsystem={}letuserAgent=navigator.userAgent//获取微信版本letsystemInfo=userAgent.match(/MicroMessenger.*?(?=)/)if(systemInfo&&systemInfo.length>0){system.wechat=systemInfo[0]}//苹果手机......
  • 企业微信——给国外的邮箱发邮件报错Authentication results: DKIM = did not pass
    前言发件人([email protected])域名的DNS记录未设置或设置错误导致对方拒收此邮件。hostgmail-smtp-in.l.google.com[172.253.118.27]said:550-5.7.26Thismailhasbeenblockedbecausethesenderisunauthenticated.Gmailrequiresallsenderstoauthenticatewitheither......