Skip to content
Advertisement

Problems getting data on event change vue and laravel

I’m having a hard time getting data from an event triggered by a change in a select, let me show you the code:

This is the select:

<b-col md="4" sm="12">
                <b-form-group label="Tipo: " label-for="tipo">
                    <input type="hidden" v-model="maintenance.typeId" name="tipoId" id="tipoId">
                    <b-form-select id="tipo" :options="options" :readonly="mode === 'remove'" @change="selecionar($e)"></b-form-select>
                </b-form-group>
            </b-col>

This is the method:

selecionar(e){
            var tipo = e.target.value
            const url = this.rotatipoautcomp

            axios.get(`${url}?${parseInt(tipo)}` + parseInt(tipo), this.manutencoes).then(res => {
                this.manutencoes = res.data
                return console.log(this.parseInt(tipo))
            })
        }

This is the function in the controller:

public function ajaxServices(Request $request)
{
    $tipo = Input::get('tipo');
    /*$tipo = $request->tipo;*/

    //$tipoSelection = TecManutencaoTipo::where('tipo', '=', $tipo)->select('tipo')->first();

    $tiposSelected = TecManutencaoTipo::select('manutencao AS value')->where('tipo', '=', $tipo)->get();

    $dados = [];

    if($tiposSelected){
        $dados = $tiposSelected;
        //Log::info($dados);
        return $dados;
    } else {
        return response()->json($dados, 422);
    }
}

That’s the route:

Route::get('ajax-tipo', ['as'=>'tecelagem.manutencao.cadastro.ajax-tipo', 'uses' => 'TecelagemManutencaoController@ajaxServices']);

In payloads on Vue Developer Tools i get the values that i expect but still get the error:

[Vue warn]: Error in v-on handler: “TypeError: Cannot read property ‘target’ of undefined”

Since i’m new on vue, i didn’t manage to solve this.

I’ve been searching in a lot of places but didn’t found anything that could help me.

Can anyone help me please?

If there’s any information needed just tell me.

Advertisement

Answer

i managed to get the data like this in the function:

selecionar(value){
            console.log(value)
        }

Thanks for all help and time.

Advertisement