[TOC]
### 1. wxml (模板)
~~~
<view class="m-container">
<image src="{{image}}" class="m-banner {{isPlay?'rotate':''}}"></image>
<image src="{{isPlay?play:pause}}" class="m-play" bind:tap="onMusic"></image>
<image src="images/music.png" class="m-icon"></image>
<view class="text">{{content}}</view>
</view>
~~~
### 2. wxss (模板)
~~~
.m-container{
display: flex;
align-items: center;
flex-direction: column;
}
.m-banner{
width:400rpx;
height:400rpx;
border-radius: 50%;
}
.m-icon{
top:-100rpx;
left:-300rpx;
width:46rpx;
height:142rpx;
position: relative;
}
.m-play{
width:100rpx;
height:100rpx;
position: relative;
top:-230rpx;
}
.rotate {
animation: rotate 6s linear infinite;
}
@keyframes rotate {
0% { transform: rotate(0);}
100% { transform: rotate(360deg);}
}
~~~
### 3. js (模板)
~~~
// components/classic/music/index.js
const audio = wx.getBackgroundAudioManager();
Component({
/**
* 組件的屬性列表
*/
properties: {
image: String,
content: String,
url: String,
title: String
},
/**
* 組件的初始數據
*/
data: {
isPlay: false,
play: "images/play.png",
pause: "images/pause.png"
},
/**
* 組件的方法列表
*/
methods: {
onMusic() {
if (this.data.isPlay) {
audio.pause();
this.setData({
isPlay: false
})
} else {
audio.title = this.properties.title;
audio.src = this.properties.url;
this.setData({
isPlay: true
})
}
},
_recoveryMusic() {
if (audio.src == this.properties.url) {
this.setData({
isPlay: true
})
}
if (audio.paused) {
this.setData({
isPlay: false
})
}
},
_monitorMusic() {
//點播放,開始
audio.onPlay(() => {
this.setData({
isPlay: true
})
})
//點暫停,不播放
audio.onPause(() => {
this.setData({
isPlay: false
})
})
//關掉的時候,不播放
audio.onStop(() => {
this.setData({
isPlay: false
})
})
//歌曲放完的時候,自動停止
audio.onEnded(() => {
this.setData({
isPlay: false
})
})
}
},
attached() {
this._recoveryMusic();
this._monitorMusic();
}
})
~~~
### 4. wxml (使用)
~~~
<v-music wx:if="{{classic.type==200}}" url="{{classic.url}}" image="{{classic.image}}" content="{{classic.content}}"></v-music>
~~~
### 5. js (使用)
~~~
onLoad: function (options) {
classicModel.getLatest(res => {
this.setData({
classic: res,
like:res.like_status,
count:res.fav_nums
})
})
},
~~~
### 6. 載次封裝http
~~~
import {
HTTP
} from "../utils/http";
class ClassicModel extends HTTP {
getLatest(callback) {
this.request({
url: "/classic/latest",
success: res => {
let index = res.index;
callback(res);
wx.setStorageSync('latest', res.index)
}
})
}
getClassic(index, nextOrprevious, callback) {
/* 有緩存則取緩存沒有緩存,則發送http */
const key = (nextOrprevious == "next") ? this._getKey(index + 1) : this._getKey(index - 1);
const classic = wx.getStorageSync(key);
if (classic) {
callback(classic);
} else {
this.request({
url: `/classic/${index}/${nextOrprevious}`,
success: res => {
callback(res);
wx.setStorageSync(this._getKey(res.index), res);
}
})
}
}
isFirst(index) {
return index == 1 ? true : false
}
isLatest(index) {
const latest = wx.getStorageSync('latest');
return index == latest ? true : false;
}
_getKey(index) {
return "classic" + index;
}
}
export {
ClassicModel
};
~~~
- 前期準備
- 軟件安裝配置
- 語法 以及 功能 的實現
- 小程序中的 輪播
- 翻轉輪播
- 實現 跳轉 頁面
- 詳談 跳轉頁面
- for 循環 渲染 頁面(重點)
- 點擊 改變 元素內容
- 功能 封裝(創建、使用 模板)(重點)
- js模塊化(重點)
- if-else實現 三目運算
- 底部導航欄tabBar 實現
- 小程序中的 函數調用 方法
- 小程序中的 block 包裹元素
- 小程序中的 hover事件
- import 標簽(重點)
- 其他
- 在本地模擬接口取數據
- 點擊跳轉 并將該元素的id一起傳遞給跳轉的頁面
- 點擊詳情頁顯示
- 點擊事件(bindtap/catchtap)
- 圖片的mode屬性
- 跳轉頁面時實現頂部顯示頁面標題
- hello world
- 將豆瓣服務器接口設置在本地
- 組件
- 地圖
- 下拉刷新
- 數據加載 loading...
- 動態設置導航(title設置)
- 實現js代碼的模塊化
- 傳參
- 組件中的生命周期函數
- 實戰
- 發送http請求
- 可用的豆瓣接口
- 處理豆瓣列表頁的數據
- 從接口上取數據渲染到頁面上1
- 從接口上取數據渲染頁面實現瀑布流2
- 瀑布流
- 音樂播放
- 文章詳情頁
- 音樂播放組件
- 音樂播放 最終版
- 電影(封裝取數據渲染)
- 分享與收藏
- 搜索框
- 將電影列表數據放緩存
- 零碎知識點
- 談組件
- 請求封裝 (重點)
- 實現簡單需求的請求失敗的封裝
- 使用class實現顯示各種錯誤信息
- 再次封裝帶class的請求實現改變里面給的url
- 使用promise 封裝http
- promise
- generator
- 01.介紹
- 02. 基本
- 03. 實例
- 04.yield
- asyns
- 01. 介紹
- 02. 使用
- 03. 取豆瓣
- 子組件(模板文件)接收父組件傳來的參數并改變其值
- 模塊化
- 在模板中提取相同的部分behavior
- 字符串與數組之間的轉換
- 子組件向父組件傳參
- 談 triggerEvent
- 整體展示
- 父組件向子組件傳wxml (在兩個組件比較相似的情況 定義卡 槽傳 wxml)
- 傳css (在父組件中定義子組件的樣式)
- 使用wxs給wxml傳js
- 點贊
- 小程序中的正則
- 組件中實現下拉刷新
- 用戶授權
- 組件點擊圖片獲取信息
- 說明
- 小程序上下滑動