图片链接复制到浏览器正常显示,直接卸载src标签里面也可以正常显示,求指教!
服务器自己的,没开防盗链!!!
报错提示
Failed to load image https://www.kjch.xyz/update2/images/wx90694dade63fe709.o6zAJs6GT7ALFlx70UXyHFtL_xuU.lkPgh3cgzSpG2f3d906f016e21895d4ade0976ff6d5c.png
the server responded with a status of 404 (HTTP/1.1 404)
From server 120.79.54.134
完整代码
<!--index.wxml--> < view class = "container" > < button bindtap = 'chooseImageTap' >上传图片</ button > < view wx:if = "{{xyz!=null}}" > <!--<image src="{{(xyz)?xyz:'640.jpg;'}}"></image>--> < image src = "{{xyz}}" ></ image > {{xyz}} </ view > </ view > |
JS代码
//index.js Page({ /** * 页面的初始数据 */ data: { imgs: [], //本地图片地址数组 picPaths: [], //网络路径 xyz: "null" , abc: null }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, //添加上传图片 chooseImageTap: function () { var that = this ; wx.showActionSheet({ itemList: [ '从相册中选择' , '拍照' ], itemColor: "#00000" , success: function (res) { if (!res.cancel) { if (res.tapIndex == 0) { that.chooseWxImage( 'album' ) } else if (res.tapIndex == 1) { that.chooseWxImage( 'camera' ) } } } }) }, // 图片本地路径 chooseWxImage: function (type) { var that = this ; var imgsPaths = that.data.imgs; wx.chooseImage({ sizeType: [ 'original' , 'compressed' ], sourceType: [type], success: function (res) { console.log(res.tempFilePaths[0]); that.upImgs(res.tempFilePaths[0], 0) //调用上传方法 console.log(res.tempFilePaths[0]) that.abc(res.tempFilePaths[0]) } }) }, //上传服务器 upImgs: function (imgurl, index) { var that = this ; wx.uploadFile({ url: 'https://www.kjch.xyz/update2/uploadFile.do' ,// filePath: imgurl, name: 'file' , header: { 'content-type' : 'multipart/form-data' }, formData: null , success: function (res) { console.log( "返回值:" + res) //接口返回网络路径 var data = JSON.parse(res.data) that.data.picPaths.push(data[ 'msg' ]) that.setData({ picPaths: that.data.picPaths, }) console.log(that.data.picPaths) } }) }, abc: function (e) { //该函数用于和后台交互 var that = this ; wx.request({ url: 'https://www.kjch.xyz/update2/url' , //仅为示例,并非真实的接口地址 data: { URL: e, }, header: { 'content-type' : 'application/json' // 默认值 }, success(res) { console.log( "abc返回值:" + res.data); that.setData({ xyz: res.data }) } }) console.log(that.xyz) } }) |
报错提示:
解决了吗,同问
大胆猜测,加了防盗链
到底是为啥
异步加载的问题,解决了吗
wx:if="{{xyz}}",和加载异步有关系吧
https://www.kjch.xyz 在小程序的业务域名配置了吗?
自己的tomcat服务器,没开防盗链
这种一般都是网站资源防盗链设置的,如果是你的站点可以选择接触限制,不是的话想办法保存起来再用自己的url吧。