【发布时间】:2017-11-02 03:29:17
【问题描述】:
下面是来自 Element-UI 网站的卡片组件示例。我的问题是如何绑定从 API url 接收的数据?
<el-row :data="hot_project_card"> //data binding -- is this correct?
<el-col :span="8" v-for="(o, index) in 2" :key="o" :offset="index > 0 ? 2 : 0">
<el-card :body-style="{ padding: '0px' }">
<div style="padding: 14px;">
<span>Yummy hamburger</span>
<template scope="scope"> {{ scope.project_name }} </template> // code is not working
</div>
</el-card>
</el-col>
</el-row>
从api接收到的数据是数组类型
export default {
data() {...}
return {
...
hot_project_card: {
fields: [{
project_name: '',
project_hot: '',
...
}]
},
...
}
后端服务器提供的api
method(): {
project_card_display () {
this.$http.get('http://127.0.0.1:8000/api/project_card_display').then((response) => {
var res = JSON.parse(response.bodyText)
console.log(res)
if (res.error_num === 0) {
this.hot_project_card = res['list'] // data recevied from backend server is saved to hot_project_card
} else {
this.$message.error('retrieved error"')
console.log(res['msg'])
}
})
}
}
【问题讨论】:
标签: vue.js vue-resource