跨域不成功
module.exports = {
// http://localhost:8080/api/test
// =>
// http://localhost:8080/test
devServer: {
proxy: {
'/api': {
// target: 'http://localhost:8080',
target: 'http://django.t.mukewang.com',
changeOrigin: true,
pathRewrite: {
// '^/api': '' // 需要重写的URL
}
}
}
}
}<template>
<div class="page-home">
<h1>旅游网</h1>
</div>
</template>
<script>
// @ is an alias to /src
// import axios from 'axios'
import { ajax } from '@/utils/ajax'
export default {
name: 'HomeView',
components: {
},
created () {
// ajax.get('http://django.t.mukewang.com/api/system/slider/list/?types=11').then(resp => {
ajax.get('http://localhost:8081/api/system/slider/list/?types=11').then(resp => {
console.log('返回的结果:', resp)
}).catch(err => {
console.log('请求出错:', err)
})
}
}
</script>
<style lang="less" scoped>
.page-home {
}
</style>
9
收起
正在回答 回答被采纳积分+1
1回答
好帮手慕小猿
2024-04-03 12:06:14
同学,你好!同学代码没有问题,由于网站 http://django.t.mukewang.com 有变更。访问http://django.t.mukewang.com/api/system/slider/list/?types=11 没有内容

访问http://localhost:8081/api/system/slider/list/?types=11时跳转到http://django.t.mukewang.com/api/system/slider/list/?types=11也是没有内容的,所以跨域是失败的。建议先理解代码,有机会再尝试跨域操作。
祝学习愉快~
Python全能工程师
- 参与学习 人
- 提交作业 16416 份
- 解答问题 4469 个
全新版本覆盖5大热门就业方向:Web全栈、爬虫、数据分析、软件测试、人工智能,零基础进击Python全能型工程师,从大厂挑人到我挑大厂,诱人薪资在前方!
了解课程

恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星