admin管理员组文章数量:1538748
uniapp项目开发中存在外部浏览器访问页面存在跨域问题!(谷歌浏览器预览,目前小程序和App调试不存在跨域问题!)
- 跨域:简单说:就是浏览器访问A域名下面的js,js请求非访问域名(A)的B域名拿取接口数据。(前提服务器不予许跨域;目前开发自启服务基本不能跨域)
- 如下图所示,访问本地服务页面,该页面js逻辑发起网络请求拿取数据;
- 存在接口访问域名拿取不到接口数据,并提示使用插件“Allow-Control-Allow-Origin”;下载链接:插件下载
- 将下载之后插件,放入谷歌浏览器插件管理;
- 刷新页面请求,跨域解决了!
- 整体demo代码:
<template> <view> <scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll" v-for="(item,key) in list" :key="key" style="height: 300px; background: #4CD964;"> <view id="demo1" style="margin: 10px; padding: 70px; background: #555555;">{{item.content}}</view> </scroll-view> </view> </template> <script> export default { data() { return { scrollTop: 0, old: { scrollTop: 0 }, list:[] } }, onLoad() { this.requestListData(); }, methods: { upper: function(e) { debugger console.log('触发刷新') }, lower: function(e) { debugger console.log('触发加载') }, scroll: function(e) { console.log('触发滚动') }, goTop: function(e) { this.scrollTop = this.old.scrollTop this.$nextTick(function() { this.scrollTop = 0 }); uni.showToast({ icon:"none", title:"纵向滚动 scrollTop 值已被修改为 0" }) }, /** * 网络请求--列表数据 * @param {type} */ requestListData(){ var myData = "https://xmkj7.test2.59iedu:8443/mobile/home/mobileMessage/getMessagePage" + this.requestGetParamStr({ pageNo: 1, pageSize: 8, categoryType: 'TRAINING_NOTICE'}) uni.request({ url: myData, data: { }, header: { 'custom-header': 'hello' //自定义请求头信息 }, success: (res) => { console.log(res.data); this.list = res.data.data.noticeList } }); }, requestParam(params) { let requestParams = { head: { appVersion: '1.0.0', //微信版本号 osPlatform: '1.0.0', //平台 系统版本号 requestTime: '2019.08.05' //请求时间 }, data: null } requestParams.data = params return requestParams }, /** * GET请求参数 拼接 ?requestString */ requestGetParamStr(params) { return '?requestString=' + encodeURI(JSON.stringify(this.requestParam(params))) } } } </script> <style> </style>
版权声明:本文标题:uniapp项目开发中存在外部浏览器访问页面存在跨域问题!(谷歌浏览器预览,目前小程序和App调试不存在跨域问题!) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1726982701a1092987.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论