英文:
Vue bootstrap table: button in column not rendering
问题
我有一个使用Vue Bootstrap的表格,其中有一个名为"cosimo"的列,其中包含一个按钮,用于启动一个模态框。然而,按钮未正确呈现并且在点击时不起作用。以下是该列的代码:
columns: [
{
title: "Cosimo",
field: "component.name",
sortable: true,
formatter: (value, row, index) => {
return `
<b-button v-b-modal.modal-1 @click="showModal">
Launch demo modal
</b-button>
`;
}
}, ...]
我已经查看了Vue Bootstrap文档,并相信我已经遵循了正确的语法来创建一个启动模态框的按钮。然而,按钮不起作用,HTML未正确呈现。有谁能帮助我找出问题所在吗?提前感谢!在模板部分以外的地方可以正常工作。
编辑
我使用以下代码呈现该列:
<bootstrap-table
ref="table"
:columns="columns"
:data="data"
:options="options"
@on-load-success="tableLoaded"
>
<template v-slot:cell(component.name)>
<span><b-btn @click="showModal(item)">Launch Demo Modal</b-btn></span>
</template>
</bootstrap-table>
然后是列的定义:
{
title: "Cosimo Recommendation",
field: "component.name",
sortable: true
},
英文:
I have a Vue Bootstrap table with a "cosimo" column that includes a button to launch a modal. However, the button is not rendering properly and does not work when clicked. Here is the code for the column:
columns: [
{
title: "Cosimo",
field: "component.name",
sortable: true,
formatter: (value, row, index) => {
return `
<b-button v-b-modal.modal-1 @click="showModal"
>Launch demo modal</b-button
>
`;
}
}, ...]
I've checked the Vue Bootstrap documentation and I believe I've followed the correct syntax for creating a button that launches a modal. However, the button is not working and the HTML is not rendering properly. Can anyone help me identify the issue? Thanks in advance! It works outside the table in the template part.
EDIT
I am rendering the column with this code:
<bootstrap-table
ref="table"
:columns="columns"
:data="data"
:options="options"
@on-load-success="tableLoaded"
>
<template v-slot:cell(component.name)>
<span><b-btn @click="showModal(item)">Launch Demo Modal</b-btn></span>
</template>
</bootstrap-table>
And then the columns entry:
{
title: "Cosimo Recommendation",
field: "component.name",
sortable: true
},
答案1
得分: 2
我不确定您正在使用的bootstrap-vue版本,但如果您使用的是2.23.0版本,那么您可以使用插槽来添加按钮和其他HTML元素,可以查看文档中关于信息模型按钮的示例:
https://bootstrap-vue.org/docs/components/table#complete-example
英文:
I'm not sure which version of bootstrap-vue you're using, but if you're on version 2.23.0, then you can use slots for adding buttons and other HTML elements, see below example of info model button in documentation:
https://bootstrap-vue.org/docs/components/table#complete-example
答案2
得分: 1
你可以通过在模板本身中使用 slot
来实现特定列的目标。
<b-table :items="items" :fields="fields">
<template v-slot:cell(<component.name>)="{ item }">
<span><b-btn @click="showModal(item)">启动演示模态窗口</b-btn></span>
</template>
</b-table>
你可以在这里看到 cell({key})
插槽的使用示例。
英文:
You can achieve this by using slot
in the template itself for that particular column.
<b-table :items="items" :fields="fields">
<template v-slot:cell(<component.name>)="{ item }">
<span><b-btn @click="showModal(item)">Launch Demo Modal</b-btn></span>
</template>
</b-table>
You can see cell({key})
slot here
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论