JavaScrip和vue,判断图片url是否有效

                //判断图片是否存在
                is_img_url(imgUrl) {
                    return new Promise(function (resolve, reject) {
                        var ImgObj = new Image(); //判断图片是否存在
                        ImgObj.src = imgUrl;
                        ImgObj.onload = function (res) {
                            if (this.complete == true) {
                                resolve(true); //正常返回true
                            }
                        }
                        ImgObj.onerror = function (err) {
                            resolve(false) //  图片异常 就返回false
                        }
                    })
                },
                //调用

                    is_img_url(self.addData.exhibit_img).then((res) => {
                        if (res) {
                            alert('请填写有效的远程图片链接');
                            return false;
                        }
                    });


Jsky博客
请先登录后发表评论
  • 最新评论
  • 总共0条评论