Vue v-使用Laravel和Vuejs进行无数据显示

时间:2019-08-05 03:32:10

标签: laravel vue.js axios vue-component

我正在使用v-foraxios来显示数据,但是当我运行我的网站时,数据不会显示,但是控制台和vue开发人员工具中都没有错误,我可以看到数据在里面。有人可以帮我吗?

enter image description here enter image description here Users.vue

 <table id="table" class="table table-striped table-bordered">
                      <thead>
                        <tr>
                          <th>Id</th>
                          <th>Name</th>
                          <th>Email</th>
                          <th>Type</th>
                          <th>Created</th>

                        </tr>
                      </thead>
                      <tbody>
                    <tr v-for="user in users.data" :key="user.id">
                        <td>{{user.id}}</td>
                        <td>{{user.name}}</td>
                        <td>{{user.email}}</td>
                        <td>{{user.type}}</td>
                        <td>{{user.created_at}}</td>
                        </tr>
                      </tbody>
    </table>

script>
    export default {
       data() {
    return {

      users: {},
      form: new Form({
        id:'',
        name: "",
        email: "",
        password: "",
        type: "",
      })
    };
  },
  methods: {
      loadUsers(){
           axios.get("api/user").then(({ data }) => (this.users = data));
      }
  },
    created() {
            console.log('Component mounted.')
            this.loadUsers()

        }
    }

</script>

api.php

Route::apiResource('user', 'API\UserController');

UserController.php

<?php

namespace App\Http\Controllers\API;


use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;
class UserController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return User::all();
    }

}

1 个答案:

答案 0 :(得分:2)

尝试一下...

<tr v-for="user in users" :key="user.id">