P粉1455438722023-08-31 00:57:07
问题出在v-for上,你可以尝试使用:v-for="results in APIData.results"
,因为"results"不是一个访问器,而是你给数组中的每个值分配的名称,而APIData不是一个数组。
P粉4818158972023-08-31 00:28:43
如果你只想循环遍历APIData
中的results
:
new Vue({ el: '#demo', data() { return { APIData: { "count": 1, "next": null, "previous": null, "results": [ { "url": "http://localhost:8000/v1/users/1/", "username": "admin", "email": "admin@example.com", "groups": [] }, { "url": "http://localhost:8000/v1/users/1/", "username": "user", "email": "user@example.com", "groups": [] } ] } } }, })
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="demo"> <template> <div> <h1> Users </h1> <div v-for="result in APIData.results" :key="result.username"> <h5>{{ result.username }}</h5> <p>{{ result.email }}</p> </div> </div> </template> </div>