小程序学习

来源:互联网 发布:vb 数组长度 编辑:程序博客网 时间:2024/06/16 14:22

1.小程序使用wxParse解析html(http://blog.csdn.net/tang05709/article/details/54924675)

2 wx.navigateTo({ url: '../city/city'}); //打开地址

wx.switchbar

3.//添加数据

 that.setData({

      main_content: main_content

 })

3.1循环

wx:for="{{myCoupons}}" wx:key="{{index}}"

4.标题

{

    "navigationBarTitleText": "标题"

}

5.

//模板和模块化两个概念,嗯

common.js文件

//返回首页
function backHome() {
  wx.switchTab({
    url: '../index/index'
  })
};

//引用页面js文件这样写

模块化module.exports 来暴露模块接口

在需要使用这些模块的文件中,使用 require(path) 将公共代码引入

var common =require('common.js');

 // 返回首页
  backHome: function () {
    common.backHome();
  },


一、微信小程序阻止冒泡事件

  事情的bind  改成 catch    bind是阻止不了冒泡的

   bindtap事件 改成 catchtap 即可阻止事件冒泡

二、点击获取当前元素id

 addCar: function (obj) {

console.log(obj.target.id);

}

pages

三.加载完成取消

var that = tjhis记得作用域

传属性记得不能写驼峰形式

小程序延时

setTimeout(function(){
    var allindex = that.data.allindex;
    console.log("wwwww", allindex);
  },300)

四 :if判断

<view wx:if="{{inform.low_price == inform.high_price}}">¥{{inform.low_price}}</view> 
                <view wx:else>¥{{inform.low_price}}~{{inform.high_price}}</view>

五,字符串替换

var s1 = s.replace(/:/g, 'b');
    var s2 = s1.replace(/,/g, 'a');


六:wx:if="{{item.success_time == 0 && item.group_expire > nowTime}}"

wx:if 并且

七:获取data-name 传来的参数

e.currentTarget.dataset.ontap

八:页面路径跳转传参

../inform/inform?gid=2

接收  :在onload里边接收

onLoad: function (options) {
    var that = this;
    var gid = options.gid;//列表页传来的id
    console.log("gidqqqqq", gid);
    this.setData({
      gid: gid,
    });
  },

九:缓存

存缓存wx.setStorageSync('dizhi', res);

取缓存wx.getStorageSync("dizhi");

十:

post请求

method: "POST",(不加header)

get请求

method: 'GET',

header: {

      'Content-Type': 'application/json'

    },

十一:wx:if    wx:else 判断

wx:if并集   wx:if="{{item.success_time == 0 && item.group_expire > nowTime}}"

十二:层级不能超过五层,可以吧不需要的页面用redirectTo 进行打开

  • navigateTo 不会将旧页面出栈;
  • redirectTo 会将旧页面出栈,再将需要跳转到的页面入栈;
  • navigateBack 则是将页面栈最后一个元素出栈,因此倒数第二个元素会成为最后一个元素,即变成「当前页面」。

十三:

  // 生成二维码
  erwei: function () {
    var sign = wx.getStorageSync("sign");
    wx.request({
      url: '请求地址?sign=' + sign,
      success:function(res){
        console.log("二维码",res);
        if(res.data.status){
          var url = res.data.url;
          wx.previewImage({
            current: url, // 当前显示图片的http链接
            urls: [url] // 需要预览的图片http链接列表
          })
        }
      }
    })
十四、改变radio,switch大小颜色 

radio{transform:scale(.8) }

<radio value="{{item.amount}}" checked="true" color="#ff4444"/>

switch{transform:scale(.8)}

十五、背景图片不支持本地,可以将其上传到网络上边或者转化base