dongzha5934 2016-12-29 00:34
浏览 50
已采纳

我在数据库中有2条记录Vue输出8条记录

i am building an online casino using Laravel 5 and Vue JS. i have managed to figure out on my own how to output recently created games for my casino. It's a basic coin flip project and I have been able to figure out how to differentiate between games that are in progress and games that are waiting for a player to join.

However, I have created an application that reads a list of available games outputted to a JSON route in routes.php. I use Vue resource to read that JSON output, however, when I view the application in the web browser, I see eight different entries from the JSON that have nothing to do with the database. I am expecting two records to be displayed in the browser, yet 8 empty records are shown. I only have 2 records in my MySQl database.

i have two alternating templates that are displayed to the user. one if the game is joinable and the other if it's in progress. The JSON file outputted by Laravel is not read by the Vue application and instead, 8 blank records are displayed on the page. I spent the last two days trying to figure ou this problem and I seem to be stuck. here is my code

Viewgames.blade.php

@extends('app')


@section('content')
    <strong>Below is a list of joinable games</strong>
    <div class="container">
    <games></games>
    </div>

  <div id="games-list">
      <template id="games-template">



          <ul class="list-group">
              <li class="list-group-item" v-for="game in games">
                 <div v-if="game.ready === 'Y'">
                     <strong>play against @{{ game.player1 }}</strong>
                 </div>
              <div v-else>
                  <strong>in progress</strong>
              </div>
          </ul>

      </template>



  </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue-resource/1.0.3/vue-resource.js"></script>

    <script src="js/all.js"></script>
@endsection

all.js

.component('games', {
template: '#games-template',


data: function() {
    return {

        games: []


    }



},


   created: function() {
        this.$http.get('api/games').then(function (games) {
            this.games = games;

        }.bind(this));
    },

});

new Vue({
    el: 'body'


});

EDIT: Controller with query:

Route::get('api/games', function() {

return App\Games::where('ready', 'Y')->get();

});

Any help is greatly appreciated!

  • 写回答

1条回答 默认 最新

  • douba4824 2016-12-29 01:03
    关注

    You must be sure this.$http.get response. Chrome Developer Tools helps you to view a reponse data. If response data has eight records, the problem is not in client side but in server side.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!