mercredi 7 juin 2017

How to pass a variable from laravel 5.4 to vuejs

Is it possible to pass a variable from controller to vuejs? I have read some answers but nothing seems to work for me. I want to pass the variable $url to vue. I have tried some thing like this

var url = {!! $url !!}; this gives me syntax error in app.js

Controller

class SearchCompanyName extends Controller
{
    public function getcompanyname($name)
    {
      return "http://ift.tt/2s4eYLJ" . $name . "&lang=eng&callback=JSON_CALLBACK";
    }   

    public function index()
    {  
       $url = $this->getcompanyname(Input::get("company_name_by_user"));
       return view('searchcompany', ['url' => $url]);

    }
}

vue app.js

Vue.component('search', require('./components/Searchnames.vue'));
const search = new Vue({
    el: '#search',
    data: {
    },
    method: {
        getMessages: function(){
            console.log('I am here')
        }()
    }
});

blade template

@section('content')
<div class="container">
{!! $url !!}
 <search></search>
</div>

@endsection



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire