其他分享
首页 > 其他分享> > vue 调用 sohu开放接口获取IP基本信息

vue 调用 sohu开放接口获取IP基本信息

作者:互联网

1.搜狐开发api接口地址:https://pv.sou.com/cityjson?ie=utf-8

2.在组件中拼接请求地址

创建element,作为组件
components: {
    'remote-js':{
      render(createElement) {
           return createElement('script', { attrs: { type: 'text/javascript', src: this.src }});
     },
     props: {
        src: { type: String, required: true },
    },
    } 

3.方法中使用:

var ipInfo = returnCitySN;
/*
ipinfo:数据格式
{"cip": "222.xx.137.xxx", "cid": "xxxxx", "cname": "xxxx"}

获得的IP地址为公网IP地址,不是机器IP地址
*/

4.可以再需要的地方直接使用

5.Element调用

 <remote-js src="https://pv.sohu.com/cityjson?ie=utf-8"></remote-js>

注:非原创,在网上看到过,刚好又是自己需要的,再次仅仅做为记录

标签:src,vue,IP,接口,sohu,IP地址,组件,createElement,type
来源: https://www.cnblogs.com/pushYYL/p/16481363.html