2017-09-08 7 views
3

Vueを使用して配列データをテーブルに出力する際に​​いくつかの問題があります。誰かがvueを使って値を解析してテーブルに入れるのを助けることができますか?下のコードを参照してください。 2の配列がなければ動作しますが、レスポンスを複数にする方法がわかりません。Vue配列からテーブルへの問題

enter image description here

は、これが私の中の関数であるため、

// HTML CODE

 <tbody> 
     <tr v-for="(input, index) in inputs"> 
      <th>((input.id))</th> 
      <th>((input.tracking_number))</th> 
      <td>((input.first_name))</td> 
      <td>((input.last_name))</td> 
      <td>((input.weight))</td> 
      <td>((input.description))</td> 
      <td>((input.courier))</td> 
     </tr> 
    </tbody> 

//終了HTML

// Vueのコード

 var app = new Vue({ 
     el: '#app', 
     data: { 
     inputs: [], 
     form: { 
     scanval: null 
     } 
     }, 
     methods: { 
     updatetable() { 
     this.$http.get('someroute', {params: {page: this.form}}) 
     .then(response => { 
      if (response.body != "null") { 
      console.log(response); 
      this.inputs.push({ 
       id: response.body.id, 
       tracking_number: response.body.tracking_number, 
       first_name: response.body.first_name, 
       last_name: response.body.last_name, 
       weight: response.body.weight, 
       description: response.body.description, 
       courier: response.body.courier 
      }) 
      this.form.scanval = "" 
      } else { 
      this.form.scanval = "", 
      alert("No items found") 
      } 
     }, response => { 
      alert("no item found"); 
     }); 
    }, 

答えて

2

inputsを応答本文と同じに設定するだけです。

this.inputs = response.body 

これは応答でinputs現在の値に置き換えられます。 OPは `Array.prototypeをを使用しているので、` inputs`が既に(いくつかのデータを持っていることをオフのチャンスで

this.inputs = this.inputs.concat(response.body) 
+0

:あなたはinputsへの応答を追加したいなら、あなたはinputsへの応答を連結することができます。プッシュ ')、おそらく' this.inputs = this.inputs.concat(response.body) ' – Phil

+0

@Phil Sure :)を試してみてください。 – Bert

+0

完璧なおかげで多くの男 – Slygoth

関連する問題