<el-tabs v-if="orderInvoiceData.length" class='invoice_list' v-model="currentOrderTab" @tab-click="clickOrderTab"> <el-tab-pane :label="numToStr(order.order_info.order_no)" :name="numToStr(order.order_info.order_no)" :key="order.order_info.order_no" v-for="order in orderInvoiceData"> <el-tabs v-if="!order.order_info.is_error" tab-position="left" style="height:calc(100% - 96px);" v-model="currentInvoiceTab"> <el-tab-pane :label="invoice.invoice_info.label" :key="invoice.invoice_info.label" :name="invoice.invoice_info.name" v-for='(invoice, index) in order.invoiceList'> </el-tab-pane> </el-tabs> </el-tab-pane> </el-tabs> vue3 如何点击第一个el-tabs时,自动触发对应的标签页
时间: 2023-11-11 13:27:50 浏览: 172
手动动态改变el-tabs标签页顺序
你可以在 `created` 生命周期函数中监听 `currentOrderTab` 的变化,在 `currentOrderTab` 变化时切换第二个 `el-tabs` 的选项卡,例如:
```html
<el-tabs v-if="orderInvoiceData.length" class='invoice_list' v-model="currentOrderTab" @tab-click="clickOrderTab">
<el-tab-pane :label="numToStr(order.order_info.order_no)" :name="numToStr(order.order_info.order_no)" :key="order.order_info.order_no" v-for="order in orderInvoiceData">
<el-tabs v-if="!order.order_info.is_error" tab-position="left" style="height:calc(100% - 96px);" v-model="currentInvoiceTab">
<el-tab-pane :label="invoice.invoice_info.label" :key="invoice.invoice_info.label" :name="invoice.invoice_info.name" v-for='(invoice, index) in order.invoiceList'>
</el-tab-pane>
</el-tabs>
</el-tab-pane>
</el-tabs>
```
```js
created() {
// 监听 currentOrderTab 的变化
this.$watch('currentOrderTab', (newVal) => {
// 找到对应的发票标签页名称
const invoiceName = this.orderInvoiceData.find(order => numToStr(order.order_info.order_no) === newVal).invoiceList[0].invoice_info.name;
// 切换第二个 el-tabs 的选项卡为对应的发票标签页
this.currentInvoiceTab = invoiceName;
});
}
```
这样,当你点击第一个 `el-tabs` 的选项卡时,就会自动触发对应的发票标签页。
阅读全文