Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

magi010731's avatar

Vue component only displays when I refresh the page

Greetings,

I am having a bit of an issue here. I built out a Vue component to enable autosuggest results from the database. My component works properly when it is displayed; the problem is that it will only render when I refresh the page. When I navigate to the page, the vue component doesn't display but it will appear after I refresh the page.

I'm pretty new to Vue.js, any ideas?

Here is my code:

findProperty.vue

<template>
    <div class="form-row">
        <div class="input-group my-3">
            <input v-model="query" type="text" placeholder="City, State or Zip Code..." @keyup="getData()" autocomplete="off" class="form-control input-lg" />
            <div class="input-group-append">
                <button class="btn btn-outline-primary" type="submit">Find Properties</button>
            </div>
        </div>
        <div class="panel-footer">
            <ul class="list-group">
                <a href="#" class="list-group-item" v-for="result in search_data" @click.prevent="getName(result)">{{ result }}</a>
            </ul>
        </div>
    </div>
</template>

<script>
    export default {
        data:function(){
            return{
                query:'',
                search_parameters:[]
            }
        },
        methods:{
            getData:function(){
                this.search_parameters = [];
                if (this.query.length >= 2 && this.query != '')
                {
                    axios.post('/api/queries/'+this.query).then(response => {
                        this.search_parameters = response.data;
                    });
                }
            },
            getName:function(result){
                this.query = result;
                this.search_parameters = [];
            }
        }
    }
</script>

app.js

Vue.component('find-properties', require('./components/FindProperty.vue').default);

master.blade.php

<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>flippy - @yield('title')</title>

    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}" defer></script>

    <!-- Font awesome -->
    <script src="https://kit.fontawesome.com/3eba662b46.js" crossorigin="anonymous"></script>

    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">

    <!-- Turbolinks -->
    <script src="http://unpkg.com/turbolinks"></script>
</head>
<body>
    <div id="app" class="d-flex flex-column">
        @include('components._navbar')
        @include('components._sidebar')
        <main>
            {{ $slot }}
        </main>

    </div>
</body>
</html>

index.blade.php

@section('title', 'Find Properties')

@section('header_title')
    <i class="fas fa-search-location"></i>
    Find Properties
@endsection

<x-master>
    <div id="find" class="parent bg-white">
        <div class="content_section">
            @include('components/_header')
            <div class="container mt-2">
                <div class="row mb-4 pb-4">
                    <div class="col">
                        <form method="get" action="/find">
                            @csrf
                            <find-properties></find-properties>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</x-master>
0 likes
2 replies
magi010731's avatar
magi010731
OP
Best Answer
Level 6

Well, after a bunch of messing around with it I figured out the issue. I moved my script tag to the bottom of the page and that fixed it:

<script src="{{ asset('js/app.js') }}" defer></script> 
ngajamulsoft's avatar

@magi010731 can you tell me why it can solve the problem? because it also solved my problem too. but i still didnt know why?

Please or to participate in this conversation.