Posts

Showing posts with the label axios

ReactJS - how do I update nested and “normal” state properties?

ReactJS - how do I update nested and “normal” state properties? This is how my state looks like: state constructor(props, context) { super(props, context); this.state = { show: false, btnLabel: 'GO!', car: { owner: false, manufacturer: false, color: false } }; } and this is how I modify state : state handleClickFetchPrice() { this.setState({btnLabel: 'Fetching data...' }); console.log(this.state.fetchPriceBtn); const url = 'some url'; axios.get(url) .then(res => { let car = [...this.state.car]; car.owner = res.data.owner; car.manufacturer = res.data.manufacturer; car.color = res.data.color; this.setState({car}); }) } The attribute car is updated, but fetchPriceBtn is not - the output of console.log(this.state.fetchPriceBtn); is still GO! . car fetchPriceBtn console.log(this.state.fetchPriceBtn); GO! What...

Build axios url with vue data - getting undefined

Build axios url with vue data - getting undefined I'm trying to use axios to get data from openweathermap, currently, I'm building the url by using a few methods to get the lat and lon from the user browser and then call a function that builds the url. The url is built properly and without any issues, but when I try to call the api with axios, weird stuff happens (basically I'm getting my own page html code returned to me) Here is the code: let weather = new Vue ({ el: '#weather', data: { error: '', apiUrl: '', city: '', country: '', icon: '', description: '', results: , }, methods: { getPosition: function() { if (navigator.geolocation){ navigator.geolocation.getCurrentPosition(this.getUrl); }else{ this.error = 'Geolocation is not supported.'; } }, getUrl: function(position){ let lat = position.coords.latitude; let lon...