Example of how to use jsonp plug in in vue

  • 2021-08-16 23:04:32
  • OfStack

Through jsonp simply get interface data, by the way, notice that jsonp method will automatically add callback


<template>
	<div class="sky">
		<h3> Get the city: </h3>
		<div class="skycon"></div>
	</div>
</template>

<script>
// Import jsonp Plug-ins 
import jsonp from 'jsonp';

export default{
	data(){
		return {
			
		}
	},
	created(){
		//jsonp Request data 
		this.getLocation()
	},
	methods:{
		getLocation(){
			let url = "https://apis.map.qq.com/ws/location/v1/ip?key=CAABZ-AVSAQ-RDR5L-GTBDJ-HLA4O-A5FDB&output=jsonp&_=1599182599164"
			//jsonp Method automatically adds the callback
			jsonp(url,{},(err,data)=>{
				//url Address  //{} Parameter  //(err,data) Error message, retrieved data 
				console.log(data)
			})
		}
	}
}
</script>

<style>
</style>

Summarize


Related articles: