outerNetIp.vue 1.18 KB

<template>
    <remote-js :src="src"></remote-js>
  </template>
  <!-- <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
    <script type="text/javascript">
      var Ip=returnCitySN['cip']
      var cityname=returnCitySN['cname']
      localStorage.setItem('Ip', Ip)
      alert(Ip);
    </script> -->
  <script>
 
  export default {
    name: 'OuterIp',
    data() {
      return {
        src: ''
      }
    },
    components: {
      'remote-js': {
        render(createElement) {
          return createElement('script', {
            attrs: { type: 'text/javascript', src: this.src || 'http://pv.sohu.com/cityjson?ie=utf-8' }
          })
        },
        props: {
          src: { type: String, required: true }
        }
      }
    },
    methods:{
        getIP(){
            const returnCitySN = window.returnCitySN ? window.returnCitySN : {};
            const ip = returnCitySN["cip"];
            return ip;
        }

    },
    mounted() {
        // 将组件实例挂载到全局对象上
        window.myComponentInstance = this;
    },
    unmounted() {
        // 组件销毁时移除全局对象的引用
        window.myComponentInstance = null;
    }
  }
  </script>