[TOC]
### 1. wxml (模板)
~~~
<view class="like" bind:tap="onLike">
<image src="{{like?yesSrc:noSrc}}" class="icon"></image>
<text>{{count}}</text>
</view>
~~~
### 2. js (模板)
~~~
// components/classic/like/index.js
Component({
/**
* 組件的屬性列表
*/
properties: {
like:{
type:Boolean,
value:false
},
count:Number
},
/**
* 組件的初始數據
*/
data: {
yesSrc:'images/like.png',
noSrc:'images/unlike.png'
},
/**
* 組件的方法列表
*/
methods: {
onLike(){
var like = this.properties.like;
var count = this.properties.count;
if(like){
this.setData({
like:false,
count:count-1
})
}else{
this.setData({
like:true,
count:count+1
})
}
var behavior = this.data.like
this.triggerEvent('like',{
behavior
})
}
}
})
~~~
### 3. wxml(使用)
~~~
<v-like like="{{like}}" count="{{count}}" bind:like="onLike"></v-like>
~~~
### 4. js (使用)
~~~
onLoad: function (options) {
classicModel.getLatest(res => {
this.setData({
classic: res,
like:res.like_status,
count:res.fav_nums
})
})
},
onLike(e) {
var behavior = e.detail.behavior;
var id = this.data.classic.id;
var type = this.data.classic.type;
likeModel.getLike(behavior, id, type);
},
onPrev() {
this._updateData("previous");
},
onNext() {
this._updateData("next");
},
_updateData(nextOrprevious) {
classicModel.getClassic(this.data.classic.index,
nextOrprevious, res => {
/* 更新點贊的狀態 */
likeModel.getLikeStatus(res.type,res.id,res=>{
this.setData({
like:res.like_status,
count:res.fav_nums
})
})
this.setData({
classic: res,
// 更新是否為第一期的狀態
isFirst: classicModel.isFirst(res.index),
isLatest: classicModel.isLatest(res.index)
})
})
}
~~~
### 5. modeler (再次封裝的模塊)
~~~
import {HTTP} from "../utils/http";
class LikeModel extends HTTP{
getLike(behavior,id,type){
const url = behavior?"/like":"/like/cancel"
this.request({
url,
method:"POST",
data:{
art_id:id,
type
}
})
}
/* 獲取期刊點贊的信息 */
getLikeStatus(type,id,callback){
this.request({
url:`/classic/${type}/${id}/favor`,
success:res=>{
callback(res);
}
})
}
}
export {LikeModel}
~~~
- 前期準備
- 軟件安裝配置
- 語法 以及 功能 的實現
- 小程序中的 輪播
- 翻轉輪播
- 實現 跳轉 頁面
- 詳談 跳轉頁面
- 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
- 點贊
- 小程序中的正則
- 組件中實現下拉刷新
- 用戶授權
- 組件點擊圖片獲取信息
- 說明
- 小程序上下滑動