VueJS doesn't work on mobile VueJS doesn't work on mobile vue.js vue.js

VueJS doesn't work on mobile


Your code seems to be working well, except that on codepen it gives me error XMLHttpRequest cannot load http://ipinfo.io/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://s.codepen.io' is therefore not allowed access..

You can put your domain name on headers options to enable cross-origin, here is example:

this.$http.get('http://ipinfo.io', {    'headers': {        'Origin': 'http://yourdomain.com'    }})

See example: http://bozue.com/weather.html

I also noticed you put vue.min.js and vue-resource.js scripts in wrong order that might trigger some error, vue.min.js should be on the first place.


I found a solution for this. I works on my mobile now. I believe that I will work on other browses too. The problem is that some browsers doesn't recognize the operation ">", so I changed it.

Here is the new code:

getWeather: function(){            var that = this;            this.$http.get('http://ipinfo.io', {'headers': {        'Origin': 'http://yourdomain.com'}            }).then(function(response) {                  console.log(response.data);                  that.location = response.data.city + ", " + response.data.country;                  // Get weather informaiton                  var api = 'ebd4d312f85a230d5dc1db91e20c2ace';                  var city = response.data.city;                  var url = "https://crossorigin.me/http://api.openweathermap.org/data/2.5/weather?q={CITY}&APPID={APIKEY}&units=metric";                  url = url.replace("{CITY}",city);                  url = url.replace("{APIKEY}", api);                   that.$http.post(url,{dataType: 'jsonp'},{              headers : {                'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'            }}).then(function(response) {                    console.log(response.data);                  that.temperature = response.data.main.temp;                  that.weather = response.data.weather[0]['description'];                  that.iconURL = "http://openweathermap.org/img/w/" + response.data.weather[0]['icon'] + ".png";                  }).then(function(){                      // error callback                  });              }).then(function(){                  console.log(response.data);                          });                      },