据我了解,OP在问:
“我如何强制<b-table>
组件自行(重新)排序而不要求用户单击该<b-table>
组件?”
我的回答(在他们的情况下):
- 检测提到的“可见标题”上的点击事件
- 在该单击事件的函数处理程序中,
sort-changed
从目标表发出一个事件
// Assuming an SFC (single file component)
<template>
<div>
<b-button @click="handleClick">Sort the table!</b-button>
<b-table ref="mytable" @sort-changed="handleSortChange"></b-table>
</div>
</template>
<script>
export default {
// ...
methods: {
handleClick(evt) {
/// this is called when you click the button
this.$refs.mytable.$emit('sort-changed')
}
handleSortChange(context) {
// this is called when b-table with ref "mytable" hears the 'sort-changed' event
// that it has emitted
// sorting logic goes here
}
}
//...
}
</script>