修改用戶信息之頭像 出現(xiàn)沒有域名問題

一個(gè)有域名的圖片,一個(gè)是沒有的
此代碼在進(jìn)行修改時(shí)的操作

檢查圖片

// 判斷一個(gè)url是否可以訪問
/*
我用post請(qǐng)求訪問一個(gè)url,服務(wù)端數(shù)據(jù)是一個(gè)json的txt文件,理論上直接訪問,返回json,然后解析就沒事了,可是今天很無語.居然給我返回405...

問了很多人,他們給我提供了各種思路,都不奏效.最后聽一個(gè)好哥們叫我試試換get請(qǐng)求,哎呀~~~這就解決了...

          我問他這是為什么?  大概回到就是,我訪問用post請(qǐng)求, 那么 , 當(dāng)發(fā)送的url是一個(gè)具體的資源的時(shí)候, 網(wǎng)站應(yīng)該解析的時(shí)候把整個(gè)url當(dāng)作了域名解析了.  也就是說我并沒有傳參數(shù)給服務(wù)端, 而是直接訪問服務(wù)端的具體資源, 所以要用get請(qǐng)求.
————————————————
版權(quán)聲明:本文為CSDN博主「我不知道深度的」的原創(chuàng)文章,遵循 CC 4.0 BY-SA 版權(quán)協(xié)議,轉(zhuǎn)載請(qǐng)附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/hgffhh/article/details/83821357*/
const IsLoad = function(url, fun) {
    uni.request({
        url: url,
        method: 'GET', 
        success: function(response) {
            // console.log(response)       
            if (response.statusCode === 200) {
                fun(true);
            } else {
                fun(false);
            }
        },
        error: function(res) {
            console.log(res)
            fun(false);
        }
    });
}
export default IsLoad
<template>
    <view>
        <view style="height: 80upx;"></view>
        <view class="back">
            <view class="back-a" @tap="excaimg">
                <view class="img-a">
                    頭像
                </view>
                <!-- 回顯得 -->
                <view class="img" v-if="ForAttr==true">
                    <image :src="attr"></image>
                </view>
                <!-- 拿到的 -->
                <view class="img" v-if="ForAttr==false">
                    <image :src="wz_attr"></image>
                </view>
            </view>
        </view>
        <view class="back">
            <view class="back-a" @click="name">
                <view class="img-a">昵稱</view>
                <view class="name" v-model="nickname">{{nickname}}</view>
                <view class="icon">
                    <view class="iconfont">></view>
                </view>
            </view>
        </view>
        <view class="bg" v-if='all'>
            <view class="bg-bei">
                修改姓名
                <input class="bg-input" type="text" v-model="nick" placeholder="請(qǐng)輸入昵稱" />
                <view class="bg-comment" @tap="yin">
                    <view class="ok" @change="onKeyInput">
                        確定
                    </view>
                    <view class="ok" @tap="quxiao">
                        取消
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
    import IsLoad from "../../../../common/checkImg"

    var sourceType = [
        ['camera'], //拍照
        ['album'], //相冊(cè)
        ['camera', 'album'] //拍照或相冊(cè)
    ]
    var sizeType = [
        ['compressed'], //壓縮
        ['original'], //原圖
        ['compressed', 'original'] //壓縮或原圖
    ]

    export default {
        name: 'IsLoad',
        data() {
            return {
                attr: '', //回顯得頭像
                wz_attr: '', //拿到的
                ForAttr: false,
                nickname: '', //昵稱
                nick: '',
                all: false,
                sourceTypeIndex: 2,
                sourceType: ['拍照', '相冊(cè)', '拍照或相冊(cè)'],
                sizeTypeIndex: 2,
                sizeType: ['壓縮', '原圖', '壓縮或原圖'],
                countIndex: 8,
                count: 1
            }
        },
        onLoad() {
            var that = this
            that.token = uni.getStorageSync('token')
            //獲得用戶的個(gè)人信息
            this.percha()
        },
        // 右上角的提交
        onNavigationBarButtonTap(e) {
            var that = this
            if (that.token) {
                uni.request({
                    url: this.baseUrl + 'api/User/setInfo',
                    method: 'POST',
                    data: {
                        "attr": that.attr,
                        "zfb_id": that.zfb_id,
                        "nickname": that.nickname,
                        "real_name": that.real_name,
                        "token": that.token
                    },
                    header: {
                        'Content-type': 'application/x-www-form-urlencoded'
                    },
                    success: (ret) => {
                        console.log(ret, '修改個(gè)人信息');
                        if (ret.data.code == 0) {
                            uni.hideToast();
                            uni.showToast({
                                title: '修改成功',
                                icon: 'none'
                            });
                            setTimeout(function() {
                                uni.navigateBack({});
                            }, 1500)
                        } else {
                            uni.hideToast();
                            uni.showToast({
                                title: ret.data.msg,
                                icon: 'none'
                            });
                        }
                    },
                    error: (e) => {
                        uni.hideToast();
                        uni.showToast({
                            title: e.response.data.msg,
                            icon: 'none'
                        });
                    },
                });
            } else {
                uni.hideToast();
                uni.showToast({
                    title: '請(qǐng)先去登錄!',
                    icon: 'none'
                });
                uni.navigateTo({
                    url: '../../../login/login'
                });
            }
        },
        methods: {
            percha() {
                var that = this
                if (that.token) {
                    uni.request({
                        url: this.baseUrl + 'api/User/info', //地址
                        data: {
                            "token": that.token
                        },
                        header: {
                            'Content-type': 'application/x-www-form-urlencoded'
                        },
                        method: "POST",
                        success: (ret) => {
                            // console.log("用戶信息", ret.data.data)
                            that.nickname = ret.data.data.nickname
                            that.wz_attr = ret.data.data.wz_attr
                            that.attr = ret.data.data.attr
                            that.zfb_id = ret.data.data.zfb_id
                            that.nick = ret.data.data.nickname

                            //ISimage
                            IsLoad(that.wz_attr, function(res) {
                                if (res == true) {
                                    that.wz_attr = ret.data.data.wz_attr
                                } else {
                                    that.wz_attr = '../../../../static/me/USER@2x.png'
                                }
                            });
                            // if (!that.attr) {
                            //  that.wz_attr = '../../../../static/me/USER@2x.png'
                            // }
                        },
                        error: (e) => {
                            uni.hideToast()
                            uni.showToast({
                                title: e.response.data.msg,
                                icon: 'none',
                            })
                        },
                    })
                } else {
                    uni.hideToast();
                    uni.showToast({
                        title: '您還沒有登錄哦',
                        icon: 'none'
                    })
                }
            },
            //修改頭像
            excaimg() {
                let that = this
                uni.chooseImage({
                    count: 1,
                    sizeType: ['original', 'compressed'],
                    sourceType: ['album', 'camera'],
                    success: function(res) {
                        that.attr = res.tempFilePaths[0]
                        console.log("打開相機(jī)", that.att)
                        if (res.tempFilePaths[0]) {
                            that.goFile(res.tempFilePaths[0]);
                        }
                    }
                });
            },
            goFile(attr) {
                var that = this;
                uni.uploadFile({
                    url: this.baseUrl + 'api/File/uploadFile',
                    filePath: attr,
                    name: 'file',
                    formData: {
                        token: uni.getStorageSync('token'),
                    },
                    success: (res) => {
                        console.log('圖片上傳', res)

                        uni.hideLoading();
                        uni.showLoading({
                            title: 'loading...'
                        });
                        console.log(JSON.parse(res.data).code)
                        if (JSON.parse(res.data).code == 0) {
                            uni.hideToast()
                            uni.showToast({
                                title: "上傳成功!",
                                icon: 'success'
                            });
                            // 回顯
                            that.ForAttr = false
                            that.wz_attr = JSON.parse(res.data).data.complete_file_path
                            console.log("回顯", that.wz_attr)

                            that.attr = JSON.parse(res.data).data.file_path
                            console.log("上傳", that.attr)
                        } else {
                            uni.hideToast()
                            uni.showToast({
                                title: '上傳失敗!',
                                icon: 'none'
                            });
                        }
                    }
                });
            },
            name() {
                var that = this
                that.all = true
            },
            yin() {
                let that = this
                that.nickname = that.nick
                that.all = false
            },
            onKeyInput: function(event) {
                var that = this
                this.nick = event.target.nickname
            },
            quxiao() {
                var that = this
                that.attr = that.attr
                that.nick = that.nickname
            }
        }
    }
</script>

<style>
    page {
        width: 100%;
        height: 100%;
        background-color: #F6F5FA;
    }

    .img image {
        width: 100upx;
        height: 100upx;
        border-radius: 50%;
    }

    .back-a {
        width: 80%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 116upx;
        line-height: 116upx;
        margin: 10upx auto;
    }

    .back {
        width: 100%;
        align-items: center;
        border-bottom: #BEBEBE solid 1upx;
    }

    .img-a {
        font-size: 30upx;
        font-family: pingfang-sc-regular;
        color: #333231;
        font-weight: bold;
    }

    .name {
        flex: 1;
        text-align: right;
    }

    .icon {
        width: 70upx;
        text-align: center;
    }

    /*隱藏加載*/
    .bg {
        width: 100%;
        height: 100%;
        position: fixed;
        top: 0;
        text-align: center;
        background: rgba(0, 0, 0, 0.4);
    }

    .bg-bei {
        width: 90%;
        height: 10rem;
        line-height: 1.5rem;
        background-color: #FFFFFF;
        margin: 10rem auto;
        border-radius: 10upx;
    }

    .bg-input {
        width: 100%;
        height: 200upx;
    }

    .real-input {
        width: 100%;
        height: 100upx;
    }

    .zfb-input {
        width: 100%;
        height: 100upx;
    }

    .bg-comment {
        width: 100%;
        height: 2rem;
        display: flex;
        justify-content: space-between;
    }

    .ok {
        width: 50%;
    }
</style>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 點(diǎn)擊查看原文 Web SDK 開發(fā)手冊(cè) SDK 概述 網(wǎng)易云信 SDK 為 Web 應(yīng)用提供一個(gè)完善的 IM 系統(tǒng)...
    layjoy閱讀 14,316評(píng)論 0 15
  • 敏感肌適合用嬰兒產(chǎn)品? 由于中國護(hù)膚品化妝品市場(chǎng)混亂,加之中國女性消費(fèi)者對(duì)于護(hù)膚知識(shí)的缺失,所以,市場(chǎng)上那種速效的...
    洪_fcf7閱讀 178評(píng)論 0 0
  • 時(shí)光總是這么匆匆流失,三年了,仍然記得你的電話,可我卻再也沒有勇氣去撥那一串?dāng)?shù)學(xué)。 不告而別或許是最直接了當(dāng)?shù)慕Y(jié)束...
    0ab9dbed487d閱讀 403評(píng)論 0 2
  • 有些選擇,既然是自己選的,那么,爬也要給我爬著完成,就算過程多苦多累,都要忍著,因?yàn)橹挥锌孔约毫?,你仰望的天空才?..
    半夏傾閱讀 147評(píng)論 0 1
  • 總是 在清晨醒來第一時(shí)間 看手機(jī); 總是 在工作忙完后 看看有沒有新消息; 總是 在關(guān)機(jī)后 生怕錯(cuò)過某人“晚安”的...
    燕飛新雨閱讀 1,496評(píng)論 32 25

友情鏈接更多精彩內(nèi)容