1.图片标签:

<image src="/images/aaa.png"></image>

2.文本标签:

<text>Hello</text>

3.swiper滑动轮播:

<swiper catchtap="onSwiperTap" vertical="{{false}}" indicator-dots="true" autoplay="true" interval="5000">
<swiper-item>
<image id="7" src="/images/wx.png" data-postId="3"></image>
</swiper-item>
<swiper-item>
<image src="/images/vr.png" data-postId="4"></image>
</swiper-item>
<swiper-item>
<image src="/images/iqiyi.png" data-postId="5"></image>
</swiper-item>
</swiper>

单击事件

onSwiperTap: function (event) {
// target 和currentTarget
// target指的是当前点击的组件 和currentTarget 指的是事件捕获的组件
// target这里指的是image,而currentTarget指的是swiper
var postId = event.target.dataset.postid;
wx.navigateTo({
url: "post-detail/post-detail?id=" + postId
})
}

4.wx:if:

控制图片显示隐藏

<image wx:if="{{true}}" src="/images/wx.png"></image>

5.wx:for

循环遍历

<block wx:for="{{posts_key}}" wx:for-item="item" wx:for-index="idx"></block>

 6.单击事件:

<view bindtap="sayHello"></view>
sayHello:function(){
console.log("hello");
}

7.页面跳转:

有父子关系(最多5级)

wx:navigateTo({
url:"../posts/post"
});

平行跳转

wx:redirectTo({
url:"../posts/post"
});

8.在一个js中读取另一个js中的数据:

在一个js中创建并输出本地数据

module.exports={
postList : local_database
}

在另一个js中引用并获取数据

var postsData=require('../../data/posts-data.js')

使用数据

this.setData({
posts_key:postsData.postList
});

9.template模板:

创建并定义template

<template name='postItem'></template>

在需要的wxml中引用

<import src='post-item/post-item-template.wxml'/>

在wxss中引用样式

@import 'post-item/post-item-template.wxss';

使用template并添加单击事件

<block wx:for="{{posts_key}}" wx:for-item="item">
<view catchtap='onPostTap' data-postId='{{item.postId}}'>
<template is='postItem' data='{{...item}}'/>
</view>
</block>
var postId =event.currentTarget.dataset.postid;

template传递数据的另一种方式 

<template is="starsTemplate" data="{{stars:stars, score: average}}" />

10.获取地址栏参数:

onLoad:function(option){
var postId = option.id;
}

11.小程序缓存:

缓存普通文本

wx.setStorageSync('key', "hello man");

缓存对象

wx.setStorageSync('key', {
name:"zhangsan",
age:"13"
});

获取缓存

var name=wx.getStorageSync('key');

删除缓存

wx.removeStorageSync('key');

清除所有缓存

wx.clearStorageSync();

异步缓存

getPostsCollectedAsy: function () {
var that = this;
wx.getStorage({
key: "posts_collected",
success: function (res) {
var postsCollected = res.data;
}
})
}

12.提醒showToast:

wx.showToast({
title:postCollected?'收藏成功':'取消成功',
duration:800,
icon:'success'
})

 13.showActionSheet:

onShareTap: function (event) {
var itemList = [
"分享给微信好友",
"分享到朋友圈",
"分享到QQ",
"分享到微博"
];
wx.showActionSheet({
itemList: itemList,
itemColor: "#405f80",
success: function (res) {
// res.cancel 用户是不是点击了取消按钮
// res.tapIndex 数组元素的序号,从0开始
}
})
}

 14.全局变量的与获取:

定义app.js

App({
globalData:{
g_isPlayingMusic:false
}
})

获取

var app = getApp();
var info = app.globalData.g_isPlayingMusic;

15.图片切换两种方式:

<image wx:if="{{collected}}" catchtap='onColletionTap'  src="/images/icon/collection.png"></image>
<image wx:else catchtap='onColletionTap' src="/images/icon/collection-anti.png"></image>
<image class='audio' src="{{isPlayingMusic ? '/images/music/music-stop.png' : '/images/music/music-start.png'}}"></image>

微信小程序常用控件汇总的更多相关文章

  1. 微信小程序地图控件篇 ---自定义图标被地图覆盖的问题

    今天在做微信小程序的时候遇到这个这样的问题  需要在地图上加个一个自定义的图标控件 类似这样的 刚开始的时候怎图片一直会被地图组件覆盖  ,要怎么解决这个问题  我去翻了下小程序的文档 有个cover ...

  2. 微信小程序设置控件权重

    项目中最常用的两种布局方式,水平布局和垂直布局,在微信小程序中实现起来也比较简单.       1.横向水平布局:         实现水平布局,需要四个view容器组件,其中一个是父容器.如下: & ...

  3. 微信小程序 Button控件 点击传值给JavaScript

    直接看例子吧: WXML:直接看Button,用“data-”(data-total)传值,后台如何获取,继续看下面JS代码. <view class="infothird" ...

  4. 微信小程序常用样式汇总

    本文系转载: 原文作者:chenzheng8975 原文地址:https://www.cnblogs.com/chenzheng8975/p/9605186.html 微信小程序常用样式汇总 小程序特 ...

  5. 微信小程序(应用号)资源汇总整理

    微信小应用资源汇总整理 开源项目 WeApp - 微信小程序版的微信 wechat-weapp-redux-todos - 微信小程序集成Redux实现的Todo list wechat-weapp- ...

  6. 黄聪:微信小程序(应用号)资源汇总整理(转)

    微信小应用资源汇总整理 开源项目 WeApp - 微信小程序版的微信 wechat-weapp-redux-todos - 微信小程序集成Redux实现的Todo list wechat-weapp- ...

  7. 基于 mpvue 框架的小程序选择控件,支持单列,多列,联动

    最近在学着写mpvue小程序,在做选择控件时候遇到了点问题,按照微信小程序方法picker,很不方便! 在网上搜到一个很好用的组件下面给大家分享: 组件说明文档链接:https://go.ctolib ...

  8. 微信小程序开发 (资料汇总,谁还没被坑过?希望助你绕过一些坑)

    最近帮人家做一个微信小程序,刚好想熟悉一下.由于牵扯到多用户使用系统,以及数据共享,所以自然架构选择了,客户端和服务器的方式. 后台服务器是windows server,后台程序是.Net  WebA ...

  9. ***腾讯云直播(含微信小程序直播)研究资料汇总-原创

    这段时间抽空研究了下直播技术,综合比较了下腾讯云直播的技术和文档方面最齐全,现把一些技术资料和文档归集如下: 1.微信小程序移动直播入门导读 https://cloud.tencent.com/doc ...

随机推荐

  1. 解决Cannot find config.m4 Make sure that you run '/home/php/bin/phpize' in the top level source directory of the module

    oot@DK:/home/daokr/downfile/php-7.0.0/ext/mysqlnd# /home/php/bin/phpizeCannot find config.m4. Make s ...

  2. yii2.0简单使用elasticsearch

    1.安装扩展 /c/phpStudy/PHPTutorial/php/php-5.5.38/php /c/ProgramData/ComposerSetup/bin/composer.phar req ...

  3. jquery.nicescroll.js Unable to preventDefault inside passive event listener due to target being treated as passive.

    解决办法就是:https://github.com/bestjhh/Plugin 下载替换. 参考: https://github.com/bestjhh/Plugin https://blog.cs ...

  4. StarUML自动生成Java代码

    下载一个starUML 链接:https://pan.baidu.com/s/1pIGNVmhtwBxMrCG9LHdkCQ 提取码:c4i6 复制这段内容后打开百度网盘手机App,操作更方便哦 添加 ...

  5. 【CSP模拟赛】仔细的检查(树的重心&树hash)

    题目描述 nodgd家里种了一棵树,有一天nodgd比较无聊,就把这棵树画在了一张纸上.另一天nodgd更无聊,就又画了一张.  这时nodgd发现,两次画的顺序是不一样的,这就导致了原本的某一个节点 ...

  6. OSPF区域间+NAT详解

  7. redis 业务锁 not exist 模式

    背景: 业务核心模块只能提交一次,原实现方案 前端加提交限制.后端加数据库业务逻辑判定,结果失效,api站点部署多台负载,切方法需要强求第三方接口 响应时间较慢 ,故放弃lock. 解决方案:redi ...

  8. [Windows] 输入字符间距变宽

    今天在输入时,不会到误触到哪里,输入的字符间距变得很宽,如下图: 最后找到原因是不小心同时按下了 Shift+Space(空格),进入全角模式,就会导致输入的字符间距变宽 想要恢复,再按一次 shif ...

  9. Debian9安装QT5.12.3

    打开虚拟机,打开火狐浏览器,输入网址下载QT5.12(linux版本,约13.G) download.qt.io/archive/qt/5.12/5.12.0/ 文件默认下载在Downloads文件夹 ...

  10. 7年.NET面试Java的尴尬历程

    先简单介绍LZ 现如今的情况,LZ 1992年出生,2012年实习,大专学渣一枚,实习期直接被校企合作直招到公司做.NET开发,现如今在某三线城市做后端技术经理,7年开发经验(5年.Net,2年.NE ...