【发布时间】:2019-03-30 06:18:08
【问题描述】:
我正在使用 Bootstrap Vue JS 表格组件来创建数据表: https://bootstrap-vue.js.org/docs/components/table
我是 VueJS 新手,不确定如何解决这个问题,这使得寻找解决方案变得更加复杂。
我使用 API 端点返回 JSON 数据:
{
"options":{
"filter":false
},
"fields":[
{
"key":"id",
"label":"Id",
"editLink":false,
"display":true,
"sortable":true,
"class":"shrink"
},
{
"key":"name",
"label":"Name",
"editLink":true,
"display":true,
"sortable":true
}
],
"data":[ ]
}
这是我的表格模板:
<b-table striped hover bordered foot-clone class="table-sm"
:items="users" :fields="displayedFields" :per-page="perPage" :current-page="currentPage" :filter="filter"
@filtered="onFiltered"
>
<template v-for="(field, index) in fields">
<template slot="{{field.key}}" slot-scope="row" v-if="field.editLink">
<router-link :to="'/user/' + row.item.id" v-bind:key="index"></router-link>
</template>
</template>
<template slot="status" slot-scope="row">
<toggle-button :width="36" :height="18" v-model="row.status" :labels="false" :colors="{checked: '#00FF00', unchecked: '#FF0000', disabled: '#CCCCCC'}"/>
</template>
</b-table>
第一个模板标签是来自疯狂猜测的尝试。我希望能够有条件地从字段配置中为一列选择一个表。您可以在我的尝试中看到,当该字段的配置 editLink 为 true 时,我想放置一个 RouterLink。
我怎样才能完成这项工作?
【问题讨论】:
标签: javascript vue.js bootstrap-vue