vue acquired local ip

First, the purpose

Get ip address of the current access

Second, the idea

Ip gain access through the use of Sohu's api

Three steps

1, add the index.html

<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>

2, a new component Admin.vue, call methods

 <template>
     <div>
         <h1>username:{{user.username}}</h1>
         <h1>age:{{user.age}}</h1>
         <h1>ip:{{user.ip}}</h1>
     </div>
 </template>
 
 <script>
 export default {
    data(){
        return{
            user:{
                'username':'sj',
                'age':18,
                'ip':''
            }
        }
    },
    mounted(){
        this.ready()
    },
    methods:{
        ready:function () { 
                // js incorporated <! - access to the local ip ->
                // Get the local IP address
                // <Script the src = "http://pv.sohu.com/cityjson?ie=utf-8"> 
            var returnCitySN CIP = [ "CIP"]; 
                // to objects in the field of Assignment vuedata 
            this.user.ip CIP = 
        } 
    } 
    
 } 
 </ Script> 

Third, the results show

1, Sohu website visit results

 

2, operating results

Guess you like

Origin www.cnblogs.com/JimShi/p/11302384.html