如何更新在 bootstrap-vue 中单击的按钮

How can I update the button clicked in bootstrap-vue

我正在使用 Bootstrap-Vue to display a table, and I've added in an extra column with an update button using vue-slot. I have this displaying fine, and I have a method being called when you click the button. Within that method I can access all the information on the item however I can't seem to find a way to access the button. I want to disable it and change the contents of it. How can I access the button element? I have created a codepen example here,它显示了我已设置和需要执行的操作。

HTML


<div id='app'>
    <div>{{ this.output }}</div>
    <b-table hover head-variant="dark"
             id="pages-table"
             :items="items"
             :fields="fields">
        <template slot="actions" slot-scope="data">
            <button class="btn btn-dark" @click="update(data)">Update</button>
        </template>
    </b-table>
</div>

JavaScript


new Vue({
    el: "#app",
    data: {
        output: null,
        items: [
            {
                id: 1,
                name: "Tony"
            },
            {
                id: 2,
                name: "John"
            },
            {
                id: 3,
                name: "Paul"
            }
        ],
        fields: [
            {
                key: "id",
                label: "ID",
                sortable: true
            },
            { key: "name" },
            { key: "actions" }
        ]
    },
    methods: {
        update(data) {
            // I need to disable the button here
            this.output = data;
            data.item.name = "Dave";
        }
    }
});

您可以向按钮添加动态引用

 <button class="btn btn-dark" @click="update(data)" :ref="'btn' + data.index">Update</button>

然后只需通过该 ref

访问按钮
  this.$refs["btn" + data.index].disabled = true    

这是带有示例的codepen

https://codepen.io/vlaem/pen/gNjGQE

除了索引,您还可以使用数据的 ID 属性 来创建引用 (data.item.id)

虽然个人感觉这不太对,但我认为如果我们可以跟踪相同或不同数组上所有按钮的状态会更好,可能就像下面的示例

https://codepen.io/vlaem/pen/GbBMLe