美文网首页
uniapp封装一个枚举请求

uniapp封装一个枚举请求

作者: 上海_前端_求内推 | 来源:发表于2022-10-17 15:16 被阅读0次

    1,新建一个common.js

    //const baseUrl =`http://192.192.192.183:9798` 
    import basesevers from './basesevers.js'
    const baseUrl = basesevers.request1
    const getEnumeration = (url = '', date = {}, type = '', header = {}, responseType = '') => {
        return new Promise((resolve, reject) => {
            uni.request({
                method: "get",
                url: baseUrl + url,
                data: date,
                responseType: responseType,
                header: header,
            }).then((response) => {
                let [error, res] = response;
                let tempOptions = [];
                if (res.data.length > 0) {
                        tempOptions = [] = res.data
                }
                resolve(tempOptions);
            }).catch(error => {
                let [err, res] = error;
                reject(err)
            })
        });
    }
    export default getEnumeration
    
    

    2,在main.js里引用

    import getEnumeration from './common/common.js'
    Vue.prototype.$getEnumeration = getEnumeration;
    

    3,页面里使用

    async onLoad(options) {
                var aa = await this.$getEnumeration(
                    this.$basesevers.baseService.getenumlist, {
                        TypeCode: 101
                    },
                );
                console.log(aa)
            },
    

    相关文章

      网友评论

          本文标题:uniapp封装一个枚举请求

          本文链接:https://www.haomeiwen.com/subject/gctszrtx.html