dva icon indicating copy to clipboard operation
dva copied to clipboard

在dva项目中引入本地js库已经引入成功可以调用这个本地js中的方法,但是调用本地js方法发送网络请求 前缀为locahost

Open johnsky123 opened this issue 10 years ago • 9 comments

请求的链接 是 http://localhost:8989/plangh__XXXXX/ 这样的 发送请求不成功接收不到返回数据

johnsky123 avatar Oct 26 '16 04:10 johnsky123

没明白问题点,是指发出请求的 URL 不对?

sorrycc avatar Oct 26 '16 04:10 sorrycc

嗯 本地js库发出请求的url不对应该为http://www.XXX.com/plangh_xxxx 实际发起请求的链接为http://localhost:8989/www.XXX.com/

johnsky123 avatar Oct 26 '16 05:10 johnsky123

感觉是路径问题,换成绝对路径就好了。

sorrycc avatar Oct 26 '16 05:10 sorrycc

我没有在js中写请求路径 js 请求路径是引入的js文件封装好的

johnsky123 avatar Oct 26 '16 06:10 johnsky123

@sorrycc 求大神传授方法 刚我把调用外部js的方法 写在组件外部 发起的请求还是不正确 写把调用方法 写在componentDidMount () 和 componentWillReceiveProps () 都没有反应

johnsky123 avatar Oct 26 '16 12:10 johnsky123

给个能重现的 repo 吧,还是不太能理解到问题的点。

sorrycc avatar Oct 26 '16 14:10 sorrycc

你是组件的 url 参数写错了吧,比如:

ajax({
  url: '/plangh_xxxx', // => http://www.XXX.com/plangh_xxxx 
})

ajax({
  url: 'plangh_xxxx', // => http://localhost:8989/www.XXX.com/plangh_xxxx 
})

nikogu avatar Oct 27 '16 02:10 nikogu

不是的 抱歉 我描述的不清楚 我引用了一个外部的js库 在组件render方法后 调用外部js库的方法 这个方法可以发送请求 但发送请求的 url 为 http:// localhost:8989/undefined/opensource/12345 这就造成了 无法请求到数据 实际应该发送的请求为 http://www.XXX.com/opensource/12345 这些请求的链接是外部js封装好的 我无法改变这些请求链接 我应用外部库的方法是 在index.js 中 import a from 'a.js' window.a=a export default a @sorrycc @nikogu

johnsky123 avatar Oct 27 '16 02:10 johnsky123

@johnsky123 贴关键代码吧,你首先需要搞清楚你的请求是怎么发出去的,无论内部库还是外部库,你看下它怎么发请求的不就知道了

nikogu avatar Oct 27 '16 02:10 nikogu