【发布时间】:2021-07-17 08:40:09
【问题描述】:
我正在获取<pre> 标签内的所有数据。但是,我只将 Account 表数据放入我为显示而创建的表中。同时获取其他表数据需要进行哪些更改?
下一个应用vue.js页面代码
<tbody>
<tr scope="row" v-for="(user, index) in posts" :key="user.Acc_ID">
<td>
<pre>{{user.Billings[0]}}</pre></td>
<td>{{ index + 1 }}</td>
<td>{{ user.Name}}</td>
<td>{{ user.Billings[0].[{"BillId"]}}</td>
<td>{{ user.Shippngs[0]['ShipId']}}</td>
<td>{{ user.Email}}</td>
<td>{{ user.EmailSub}}</td>
<td>{{ user.PhoneCode}}</td>
<td>{{ user.PhoneNumber}}</td>
<td>{{ user.AccAddress1}}</td>
<td>{{ user.AccAddress2}}</td>
<td>{{ user.AccDistrict}}</td>
<td>{{ user.AccCity}}</td>
<td>{{ user.BillAddress1}}</td>
<td>{{ user.ShipAddress1}}</td>
<td>{{ user.Request}}</td>
<td>{{ user.StartDate}}</td>
</tr>
</tbody>
</table>
</div>
<NuxtLink to="AccountDetailsPage">Account Information Page</NuxtLink><br> <!--Link to next page -->
<NuxtLink to="Accountbackup">Backup</NuxtLink>
</b-container>
</div>
</template>
<script>
// Importing axios to perform http methods
import axios from 'axios';
var users;
export default {
name: 'consume-rest-api',
data(){
return{
posts: null
}
},
data2(){ return{
posts2: null,
name2:null
}
},
created() { //Get method axios
axios.get(`https://localhost:44394/api/accounts`)
.then(response => {
// JSON responses are automatically parsed.
this.posts = response.data
users = response['data']
})
.catch(e => {
console.log("Error Please check the connection")
});
},
}
</script>
Asp.net core web api Get方法使用entiy框架核心同时获取三个表数据。
// GET: api/Accounts
[HttpGet]
public async Task<ActionResult<IEnumerable<Account>>> GetAccounts()
{
var products = dbObj.Accounts
.Include(p => p.Billings)
.Include(q => q.Shippngs);
return await products.ToListAsync(); ;
}
【问题讨论】:
-
调试的时候能不能把
products里面的数据全部拿到? -
我在前置标签中获取这样的数据(我省略了一些 linse){“AccId”:57303,“Name”:“Nipuni Nishadika”,“BName”:“NN store”,“PhoneCode” : 11, "Billings": [ { "BillId": 87384, "BillAddress1": "Liyanagemulla", "AccId": 57303 } ], "Shippngs": [ { "ShipId": 77443, "ShipAddress1": "Liyanagemulla" , "ShipAddress2": "Seeduwa", "AccId": 57303 } ] },
标签: vue.js axios entity-framework-core nuxt.js asp.net-core-webapi