[TOC]
# swiper,詳細api請點擊:[鏈接](https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html?search-key=swiper)
~~~
<swiper indicator-dots="true" autoplay="false" interval="3000" duration="1000">
<block wx:for="{{imgUrl}}" wx:key="index">
<swiper-item>
<image src="{{item.src}}" alt=""></image>
</swiper-item>
</block>
</swiper>
~~~
微信小程序中,變量和頁面是可以分離的,一般都將變量寫在data中
eg:*將數據放在local.js中*
~~~
var imgUrl = [
{src:"/images/banner01.png"},
{src:"/images/banner02.png"},
{src:"/images/banner03.png"},
{src:"/images/banner04.png"}
]
module.exports={
imgUrl:imgUrl
}
~~~
> module.exports={}// 模塊賦值,頁面與頁面之間數據傳輸的不二選擇
> require("xxx") // 接收模塊想要傳遞的數據
*index.js內需要數據*
~~~
// 接收"../data/local.js"內,存在module.exports內的數據
var local = require("../data/local.js")
Page({
onLoad:function(){
var bannerData = local.imgUrl;
this.setData({
imgUrl:bannerData
})
},
toggleUser(){
wx.navigateTo({
url: '../user/user',
})
}
});
~~~
*index.wxml渲染數據*
~~~
<import src="../template/banner.wxml"></import>
<template is="banner" data="{{imgUrl}}"></template>
<button bindtap='toggleUser'>user</button>
~~~
template:模板工具,減少冗余代碼。
創建template文件夾,其內創建banner頁面存放模板代碼
~~~
<template name="banner">
<swiper indicator-dots="true" autoplay="false" interval="3000" duration="1000">
<!-- <swiper indicator-dots="{{true}}" autoplay="{{true}}" interval="3000" duration="1000"> -->
<block wx:for="{{imgUrl}}" wx:key="index">
<swiper-item>
<image src="{{item.src}}" alt=""></image>
</swiper-item>
</block>
</swiper>
</template>
~~~
- 小程序環境配置
- 1.生命周期
- 頁面生命周期
- 組件生命周期
- 2.小程序組件
- 點擊事件bindtap|catchtap
- swiper輪播
- wx:for循環
- 播放音樂
- map
- tabBar底部頁面切換
- scroll-view可滾動視圖區域。
- web-view裝載顯示網頁
- priviewImage新頁面預覽照片
- chooseImage本地選擇照片
- onReachBottom上拉刷新,加載等待條
- setStorage緩存
- showToast彈出提示框
- slot父組件wxml傳遞到子組件
- form表單
- 小程序.wxs,方法在.wxml調用
- 3.組件前身:模板、模板傳參
- 4.自定義組件、組件傳參|傳wxss|wxml代碼
- 5.小程序正則
- 6.小程序頁面跳轉
- 7.open-type 微信開放功能
- 實例
- 1.第一個實例 hello world
- 2.第二個實例豆瓣電影數據渲染
- 豆瓣1.0基本版
- 豆瓣2.0升級版
- 豆瓣3.0豪華版
- 3.第三個實例多接口在同一頁面使用
- HTTP封裝
- 基礎報錯提示,類式封裝
- Promise回調,類式封裝