0.0.8 • Published 11 months ago

miniprogram-mobx-request v0.0.8

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

miniprogram-mobx-request

NPM version NPM downloads

小程序 mobx composition 请求工具

Usage

TODO

Options

TODO

Development

<!--index.wxml-->
<view style="padding: 60px;">
    <button bindtap="click">点击</button>
    <view wx:if="{{state.loading}}">
        载入中
    </view>
    <view wx:elif="{{state.error}}">
        出错了
    </view>
    <view wx:else>
        {{state.data.name}}
        {{state.data.age}}
        {{state.params[0].name}}
        {{state.params[0].age}}
    </view>
</view>
// index.ts
// 获取应用实例
import {
    compositionApiBehavior,
    onAttached,
    onDetached
} from "miniprogram-mobx-composition"
import useRequest from "miniprogram-mobx-request"

Component({
    behaviors: [compositionApiBehavior],
    setup() {
        const click = () => {
            run({ name: 'mary', age: 789 })
        }
        const { state, run, runAsync, refresh /*
             刷新 
             */, refreshAsync } = useRequest((params) => {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve({
                        name: params.name,
                        age: params.age,
                    })
                }, 6000);
            })
        }, {
            manual: true, //是否手动执行 
            debounceWait: 1000, //防抖时间 
            // loadingDelay: 2000, //loading延迟时间防止闪烁 
            // throttleWait:1000,//节流时间
        });
        return {
            state,
            click,
        }
    }
})

LICENSE

MIT