各种获取数据免费接口
1.音频接口
'/music-api' : {
target : 'https://api.cenguigui.cn/' ,
changeOrigin : true ,
rewrite : ( path ) => path. replace ( / ^\/music-api / , '' ) ,
secure : false
}
import axios from 'axios' ;
const MusicClient = axios. create ( {
baseURL: '/ music- api',
withCredentials: false ,
headers: {
'Content - Type ': ' application/ json',
}
} ) ;
export default MusicClient ;
const musicUrl = ref ( '' ) ;
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.视频接口
'/video-api' : {
target : 'https://tools.mgtv100.com' ,
changeOrigin : true ,
rewrite : ( path ) => path. replace ( / ^\/video-api / , '' ) ,
secure : false
} ,
import axios from 'axios' ;
const VideoClient = axios. create ( {
baseURL : '/video-api' ,
withCredentials : false ,
headers : {
'Content-Type' : 'application/json' ,
}
} ) ;
export default VideoClient;
const videoUrl = ref ( '' ) ;
import axios from 'axios' ;
const VideoClient = axios. create ( {
baseURL : '/video-api' ,
withCredentials : false ,
headers : {
'Content-Type' : 'application/json' ,
}
} ) ;
export default VideoClient;
3.图片接口
'/dmoe-api' : {
target : 'https://www.dmoe.cc' ,
changeOrigin : true ,
rewrite : ( path ) => path. replace ( / ^\/dmoe-api / , '' ) ,
secure : false
} ,
import axios from 'axios' ;
const ApiClient = axios. create ( {
baseURL : '/dmoe-api' ,
withCredentials : false ,
headers : {
'Content-Type' : 'application/json' ,
}
} ) ;
export default ApiClient;
const imgUrl = ref ( '' ) ;
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.文字接口
'/text-api' : {
target : 'https://api.uomg.com/' ,
changeOrigin : true ,
rewrite : ( path ) => path. replace ( / ^\/text-api / , '' ) ,
secure : false
} ,
import axios from 'axios' ;
const TextClient = axios. create ( {
baseURL: '/ text- api',
withCredentials: false ,
headers: {
'Content - Type ': ' application/ json',
}
} ) ;
export default TextClient ;
const TextUrl = ref ( '' ) ;
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服务器发送请求获取员工数据
'/api' : {
target : 'http://localhost:8080' ,
changeOrigin : true ,
rewrite : ( path ) => path. replace ( / ^\/api / , '' )
} ,
import axios from "axios" ;
export const instance= axios. create ( {
baseURL : '/api' ,
timeout : 3000
} )
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) ;
}
} ;