[TOC]
### 1. config 定義url
~~~
const config ={
base_url_api:"https://douban.uieee.com/v2/movie/"
}
export {config};
~~~
### 2. 封裝http
~~~
import {
config
} from "../config";
class HTTP {
request({url,method="GET",data={}}) {
const promise = new Promise((resolve, reject) => {
wx.request({
url: config.base_url_api + url,
data,
method,
header: {
'Content-Type': 'json',
},
success: res=> {
const statusCode = res.statusCode.toString();
if (statusCode.startsWith("2")) {
resolve(res.data);
} else {
this._show_error();
}
},
fail: err=> {
reject(err);
this._show_error();
}
})
})
return promise;
}
_show_error() {
wx.showToast({
title: '網絡錯誤',
icon: 'none'
})
}
}
export {
HTTP
};
~~~
### 3. 再次封裝
~~~
import {HTTP} from "../utils/http-p";
class MovieModel extends HTTP{
getInTheaters(){
return this.request({
url:"in_theaters"
})
}
getTop250(){
return this.request({
url:"top250"
})
}
getComingSoon(){
return this.request({
url:"coming_soon"
})
}
}
export {MovieModel};
~~~
### 4. 使用
~~~
//index.js
//獲取應用實例
import {MovieModel} from "../../models/movie-p";
const movieModel = new MovieModel();
Page({
onLoad(){
const inTheaters = movieModel.getInTheaters()
const top250 = movieModel.getTop250();
const comingSoon = movieModel.getComingSoon();
Promise.all([inTheaters,top250,comingSoon]).then(res=>{
let [inTheaters,top250,comingSoon] = res;
console.log(inTheaters);
console.log(top250);
console.log(comingSoon);
})
}
})
~~~
- 前期準備
- 軟件安裝配置
- 語法 以及 功能 的實現
- 小程序中的 輪播
- 翻轉輪播
- 實現 跳轉 頁面
- 詳談 跳轉頁面
- 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
- 點贊
- 小程序中的正則
- 組件中實現下拉刷新
- 用戶授權
- 組件點擊圖片獲取信息
- 說明
- 小程序上下滑動