我正在使用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。您可以看到我的尝试。我该如何完成这个任务?