品牌网站响应式网站有哪些,南充房产网最新楼盘,深圳线上注册公司,金融网站建设方法最后一个Web项目#xff0c;采用前后端分离。
前端#xff1a;Vue 3.0 viteelement plus
后端#xff1a;PHP
运行时前端和后端是两个程序#xff0c;前端需要时才向后端请求数据。由于是两个程序#xff0c;这就会出现跨域问题。
比如前端某个地方需要请求的接口如下…最后一个Web项目采用前后端分离。
前端Vue 3.0 viteelement plus
后端PHP
运行时前端和后端是两个程序前端需要时才向后端请求数据。由于是两个程序这就会出现跨域问题。
比如前端某个地方需要请求的接口如下所示这时就会报错。
axios.post(http://localhost/cesiumphp/index.php?actionadd, jsonObject).then((response) {console.log(response);}).catch((error) {console.error(error);});console.log(jsonString);}}
解决办法
1.将http://localhost:80注端口为80时可以省略替换为api
axios.post(api/cesiumphp/index.php?actionadd, jsonObject).then((response) {console.log(response);}).catch((error) {console.error(error);});console.log(jsonString);}}
2.在vite.config.ts中增加代理配置将http://localhost:80
import { defineConfig } from vite
import vue from vitejs/plugin-vue// https://vitejs.dev/config/
export default defineConfig({plugins: [vue()],server: {proxy: {/api: {target: http://localhost:80,changeOrigin: true,rewrite: path path.replace(/^\/api/, )}}}
})
现在不报错了。