1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<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>