1
There is a list where return all active users on the system and in the same there is a button to Edit User, when I click on this option, I open a modal, capture the user id and perform a query of the data of that user in question and, load the inputs with the fields.
However, it does not work as expected. I will present my code:
new Vue({
el: '#user-table',
data: {
users: '',
firstName: '',
lastName: '',
cpf: '',
email: '',
description: '',
billing: '',
photo: ''
},
methods: {
resetPassword: function(userId, event) {
...
},
disableUser: function(userId, event) {
...
},
callModalEditUser: function(userId, event) {
var self = this;
self.$http.get('/dashboard/usuarios/usuario/' + userId).then(function(response) {
var user = response.data.user;
self.firstName = user.first_name;
self.lastName = user.last_name;
self.cpf = user.cpf;
self.email = user.email;
self.description = user.description;
self.billing = user.billing;
self.photo = user.photo;
$('#modal-edit-user').modal();
});
}
},
ready: function() {
var self = this;
self.$http.get('/dashboard/usuarios/listar-usuarios').then(function(response) {
self.users = response.data;
});
}
});
The problem itself is in function callModalEditUser
, this is the function called for this purpose, below I show her call in HTML:
<a data-toggle="tooltip" v-on:click="callModalEditUser(user.id, $event)"
data-placement="top" title="Editar usuário"
class="btn btn-primary btn-sm edit-user">
<i class="fa fa-cog"></i>
</a>
Finally, in modal, there are inputs, I will present the forms I have tried:
<input type="text" class="form-control" v-bind:value="firstName" id="first_name" placeholder="Primeiro nome">
<input type="text" class="form-control" v-model="firstName" id="first_name" placeholder="Primeiro nome">
<input type="text" class="form-control" v-bind:value="@{{ firstName }}" id="first_name" placeholder="Primeiro nome">
<input type="text" class="form-control" v-model="@{{ firstName }}" id="first_name" placeholder="Primeiro nome">
<input type="text" class="form-control" value="@{{ firstName }}" id="first_name" placeholder="Primeiro nome">
The return of json occurs naturally with the user data, within user
get all the information needed to display on the screen.
Remembering that, I use the @{{ }}
to escape and interpret {{ }}
because my backend application is Laravel and I use Blade Template.
That was exactly the problem, I switched the
el: '#user-table'
forel: 'body'
and everything worked perfectly. Thank you.– Ewerton Melo