I've encountered an issue while trying to concatenate a URL, resulting in unexpected output. Below you'll find the code I tested along with its results.
As I am currently testing on a local server, the desired request URL is http://127.0.0.1:8000/api/posts
. However, I will eventually deploy this system to a remote server, so I can't use the request URL as it stands. Based on the code below, my goal is to fetch the current hostname and append it with the route URL, but the result is not what I expected. What could be causing this unusual behavior?
Component
created() {
var test = window.location.hostname + '/api/posts';
this.axios.get(test).then(response => {
this.posts = response.data.data;
});
https://i.stack.imgur.com/23Wu3.png
Route Api (api.php)
Route::get('/posts', 'PostController@index');