Skip to content

Instantly share code, notes, and snippets.

@liuxd
Last active June 20, 2024 23:08
Show Gist options
  • Save liuxd/f61ab45c3fd5061911ee3d25f28fe34a to your computer and use it in GitHub Desktop.
Save liuxd/f61ab45c3fd5061911ee3d25f28fe34a to your computer and use it in GitHub Desktop.
[#13 微信小程序开发心得] #編程之道

微信小程序开发心得

快速创建页面

官方提供的IDE虽然编辑功能比较弱,但是有一个功能很不错——自动创建页面基本文件。当在app.json里面增加一个pages的页面配置的时候,IDE会自动创建对应的目录和四个基本文件。这比手动一个一个创建快捷得多。

调试指定页面

把需要开发调试的页面放到app.jsonpages的第一个位置的时候,打开app就是这个页面。

点击按钮获得指定表单的值

可以在表单bindblur时间中将表单值保存起来

Page({
  listenerPhoneInput: function(e) {
    this.data.mobile = e.detail.value;
  },

  getPhoneInput: function(e) {
  	console.log(this.data.mobile)
  },
})
<view class="section">
  <input bindblur="listenerPhoneInput" type="number" />
  <button bindtap="getPhoneInput"> 登录 </button>
</view>

倒计时效果Demo

function countdown(that) {
  var second = that.data.second;

  if (second == 0) {
    that.setData({
      second: "0s"
    });

    return ;
  }

  var time = setTimeout(function(){
    that.setData({
      second: second - 1
    });

    countdown(that);
  }, 1000);
}

Page({
  data : {
    second : '倒计时效果',
  },

  demo: function(e) {
    this.data.second = 60;
    countdown(this);
  },
})
<view class="section">
  <button type="warn" bindtap="demo"> {{second}} </button>
</view>

开发时跳过URL检查

线上应用是用白名单来限定可访问的URL的,不过开发的时候这样很不方便,可以勾选【项目】里的【开发环境下不校验请求域名以及TLS版本】。

清除缓存

IDE里的【调试】->【缓存】可以清理各种本地缓存,不必专门写代码去清理。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment