各种获取数据免费接口
1.音频接口
javascript"> '/music-api':{target:'https://api.cenguigui.cn/',changeOrigin:true,rewrite:(path)=>path.replace(/^\/music-api/,''),secure:false}
java">import axios from 'axios';const MusicClient = axios.create({baseURL: '/music-api',withCredentials: false,headers: {'Content-Type': 'application/json',}
});
export default MusicClient;
javascript">const musicUrl = ref('');
javascript">
const getMusic = async () => {try {const res = await musicApi.get('/api/netease');musicUrl.value = res.data.data.play_url;console.log(musicUrl);} catch (e) {console.error("Error fetching music:", e);}
}
2.视频接口
javascript"> '/video-api':{target:'https://tools.mgtv100.com',changeOrigin:true,rewrite:(path)=>path.replace(/^\/video-api/,''),secure:false},
javascript">import axios from 'axios';const VideoClient = axios.create({baseURL: '/video-api',withCredentials: false,headers: {'Content-Type': 'application/json',}
});export default VideoClient;
javascript">const videoUrl = ref('');
javascript">import axios from 'axios';const VideoClient = axios.create({baseURL: '/video-api',withCredentials: false,headers: {'Content-Type': 'application/json',}
});export default VideoClient;
3.图片接口
javascript"> '/dmoe-api': {target: 'https://www.dmoe.cc',changeOrigin: true,rewrite: (path) => path.replace(/^\/dmoe-api/, ''),secure: false},
javascript">import axios from 'axios';const ApiClient = axios.create({baseURL: '/dmoe-api', withCredentials: false,headers: {'Content-Type': 'application/json',}
});export default ApiClient;
javascript">const imgUrl = ref('');
javascript">
const getImage = async () => {try {const res = await ApiClient.get('/random.php?return=json');imgUrl.value = res.data.imgurl;console.log(res.data);} catch (error) {console.error("Error fetching image:", error);}
};
4.文字接口
javascript"> '/text-api':{target:'https://api.uomg.com/',changeOrigin:true,rewrite:(path)=>path.replace(/^\/text-api/,''),secure:false},
java">import axios from 'axios';const TextClient = axios.create({baseURL: '/text-api',withCredentials: false,headers: {'Content-Type': 'application/json',}
});
export default TextClient;
javascript">const TextUrl = ref('');
java">
const getText = async () => {try {const res = await textApi.get('/api/rand.qinghua');TextUrl.value = res.data.content;console.log(res.data);} catch (e) {console.error("出现错误", e);}
}
5.向tomcat服务器发送请求获取员工数据
javascript"> '/api':{target:'http://localhost:8080',changeOrigin:true,rewrite:(path)=>path.replace(/^\/api/,'')},
javascript">import axios from "axios";
export const instance= axios.create({baseURL:'/api',timeout:3000
})
javascript">
const getAccount = async () => {try {const response = await instance.get('/account');tableData.value = response.data.data;console.log(tableData);} catch (error) {console.error('Error fetching account data:', error);}
};