如何在vuejs中显示以下值?

时间:2017-10-04 05:52:56

标签: javascript php html vue.js

{"status":true,"data":[{"ref_id":"22","agent_id":"68","p_id":"84","description":"i am interested"},{"ref_id":"24","agent_id":"68","p_id":"84","description":"For more information about Bootstrap and Bootstrap Glyphicons, visit our Bootstrap Tutorial.For more information about Bootstrap and Bootstrap Glyphicons, visit our Bootstrap Tutorial"}

如何使用vue js显示上述DATA值?

目前我使用,但没有工作..

 <table>
 <tbody>
     <tr v-for="post in posts">
      <td>{{ post.p_id }}</td>
     </tr>
</tbody>
</table>

1 个答案:

答案 0 :(得分:0)

您的给定数据不完整。如果给定数据为posts响应,则使用posts.data代替posts

&#13;
&#13;
var vm = new Vue({
  el: '#vue-instance',
  data: {
    posts:{"status":true,"data":[{"ref_id":"22","agent_id":"68","p_id":"84","description":"i am interested"},{"ref_id":"24","agent_id":"68","p_id":"84","description":"For more information about Bootstrap and Bootstrap Glyphicons, visit our Bootstrap Tutorial.For more information about Bootstrap and Bootstrap Glyphicons, visit our Bootstrap Tutorial"}]
    },
  }
});
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.16/vue.js"></script>
<div id="vue-instance">
 <table >
 <tbody>
    <tr v-for="post in posts.data">
      <th >Ref Id</th>
      <th >Agent Id</th>
      <th >PID</th>
     </tr>
     <tr v-for="post in posts.data">
      <td>{{ post.ref_id }}</td>
      <td>{{ post.agent_id }}</td>
      <td>{{ post.p_id }}</td>
     </tr>
</tbody>
</table>
</div>
&#13;
&#13;
&#13;