1.安装axios=>npm i axios 或者yarn add axios 或者pnpm i axios */
报错:一直info There appears to be trouble with your network connection. Retrying...
原因:网络不好
2.引入axios:import axios from 'axios'
3.使用axios调用接口http://api.ipify.org或https://ipv4.icanhazip.com/
<script>
import axios from 'axios'
export default {
data() {
return {
ip: ""
}
},
created() {
axios.get('http://api.ipify.org').then(res => {
if (res.data) {
console.log(res.data)
this.ip=res.data
}
})
}
};
</script>