HTML代码:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="https://unpkg.com/vue/dist/vue.js"></script> </head> <body> <div id="vm"> {{message}} <p>{{ip}}</p> </div> </body> <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script><!-- 这句一定要引入,这是搜狐提供的IP地址获取接口 --> <script type="text/javascript" src="index.js"></script> </html>
JS代码:
1 var vue = new Vue({ 2 el: '#vm', 3 data: { 4 message: 'Hello Vue.js!', 5 ip : '' 6 }, 7 computed : { }, 8 methods : { }, 9 mounted : function(){ 10 this.ip = returnCitySN.cip; 11 }, 12 })
看看效果: