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. leetcode解题报告(30):Detect Capital

    描述 Given a word, you need to judge whether the usage of capitals in it is right or not. We define th ...

  2. Windows下 Python 2 与 Python 3 共存

    转自:http://lovenight.github.io/2016/09/27/Windows%E4%B8%8B-Python-2-%E4%B8%8E-Python-3-%E5%85%B1%E5%A ...

  3. 【概率论】5-6:正态分布(The Normal Distributions Part III)

    title: [概率论]5-6:正态分布(The Normal Distributions Part III) categories: - Mathematic - Probability keywo ...

  4. 10、spark高级编程

    一.基于排序机制的wordcount程序 1.要求 1.对文本文件内的每个单词都统计出其出现的次数. 2.按照每个单词出现次数的数量,降序排序. 2.代码实现 ------java实现------- ...

  5. Angular动态组件

    一.主页面: app.component.html: <button (click)="load();">动态</button> 2<div #dom ...

  6. 微信小程序微信登录

    开发接口 登录 wx.login wx.checkSession 签名加密 小程序登录 小程序可以通过微信官方提供的登录能力方便地获取微信提供的用户身份标识,快速建立小程序内的用户体系. 登录流程时序 ...

  7. 《挑战30天C++入门极限》图文例解C++类的多重继承与虚拟继承

        图文例解C++类的多重继承与虚拟继承 在过去的学习中,我们始终接触的单个类的继承,但是在现实生活中,一些新事物往往会拥有两个或者两个以上事物的属性,为了解决这个问题,C++引入了多重继承的概念 ...

  8. shell history 命令

    1.history命令可以显示历史执行过的命令: 2.使用!+序号执行该序号对应的命令: 例子 $ history sed 's/haha/hello/g' test cat test cat tes ...

  9. fork()函数 图解

    code #include<stdio.h> #include <getopt.h> #include<iostream> #include<string&g ...

  10. Echarts:实现拖拽效果

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...