赞
踩
后端使用的是php:
1、不使用php自带的服务器启用服务(php think run)
2、axios请求的地址使用柚皮中的设置的服务地址,且在C:\Windows\System32\drivers\etc中的host文件设置服务地址:127.0.0.33 local.ztapi.com
3、在vite.config.js中添加设置跨域
- server: {
- proxy: {
- "^/api": {
- target: "http://local.music.com",
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/api/, "")
- },
- },
- },
4、在axios封装的http.js请求中设置
- const http = axios.create({
- baseURL: '/api',
- timeout: 6000,
- })
5、在需要请求数据的地方调用
- import http from '@/utils/http'
- import { onMounted } from 'vue'
-
- const getList = async () => {
- const res = await http.post('/api/archiveList')
- console.log('archiveList=', res)
- }
- onMounted( () => {
- getList()
- })
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。