0

I'm having a trouble why the data did not display in my table, I've been using v-for in tr to display the data info, but it did not work, Is there any wrong with my code? please check this out.It would be great if anybody could help me out, thank you so much in advance!.

But it seems it returns the data

enter image description here

table

 <tbody>
     <tr v-for="listuser in users" :key="listuser.id" :value="listuser.id" >
         <td class="pl-0">
              <a href="#" >{{listuser.username}}</a>
                  <span class="text-muted font-weight-bold text-muted d-block">Programmer II</span>
          </td>
     </tr>
  </tbody>

My Script

<script>
export default {
    data() {
        return {
            users: [],
        }
    },  
    created() {
        this.getUsers();
    },
    mounted() {
        // this.ini();
    },
    methods: {
        // ini() 
        getUsers() {
            axios.get(BASE_URL + "/users/listUsers").then(response => {
                this.users = response.users;
            });
        }
    },
}
</script>

My Controller

use App\Models\User;
public function index()
    {
        return response()->json(User::all());
    }

model

class User extends Authenticatable {
   use HasApiTokens, Notifiable, HasRoles, WithPaginate;
   use ExtendedEloquentTrait;
   protected $guard = 'users';

   protected $fillable = [     
      'username',
      'email',
      'password'
   ];
  }

1 Answer 1

2

First of all use the function call inside mount function. Secondly try the loop with the following syntax.

<tr v-for="(item,index) in users" :key="index">
          <td class="pl-0">
          <a href="#" >{{item.username}}</a>
              <span class="text-muted font-weight-bold text-muted  d-block">Programmer II</span>
           </td>
</tr>

And when you get the api response set the users like below.

this.users = response.data.users
Sign up to request clarification or add additional context in comments.

11 Comments

thanks for your response, I tried to called the function in mount function and tried your loop above but it didn't display the data at all.
what's the index used for?
index actually refers to the the current iteration value like 0,1,2,3 and so on
Just echo inside blade like this . {{users.length}} {{users}}
hah I was about to mention that in the next comments. . Well, great you figure out.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.