英文:
Emit event vuejs 3 and quasar
问题
<!-- 选项卡 -->
<div v-if="tabs" class="page-toolbar_tabs">
<q-tabs
no-caps
align="left"
narrow-indicator
indicator-color="white"
class="text-white"
@click="onTabChange"
>
<q-route-tab
v-for="(tab, index) in tabs"
:key="index"
:to="tab.path"
:name="tab.name"
:label="$t(tab.label)"
:ripple="false"
exact
/>
</q-tabs>
</div>
英文:
How to update this code to start calling the onTabChange method. Emitting the event does not work, the tabs were using the @input method which is currently not triggering anything, it won't display console.log, only when I replace this @input with @click, but then I get pointer event object, not the tab clicked.
<!-- Tabs -->
<div v-if="tabs" class="page-toolbar_tabs">
<q-tabs
no-caps
align="left"
narrow-indicator
indicator-color="white"
class="text-white"
@input="onTabChange"
>
<q-route-tab
v-for="(tab, index) in tabs"
:key="index"
:to="tab.path"
:name="tab.name"
:label="$t(tab.label)"
:ripple="false"
exact
/>
</q-tabs>
and in script I have method:
methods: {
onTabChange (tab) {
console.log("this is not called")
this.$emit('onTabChange', tab)
}
}
How to make this onTabChange pass the current tab title?
答案1
得分: 1
对于第二种解决方案,您可以在 q-tab 上使用 "@update:model-value" 事件来检测当前选项卡的更改。
英文:
For the second solution, you can use "@update:model-value" event on q-tab for detect current tab changing.
答案2
得分: 0
I have solved this by adding the click event on:
<q-route-tab
v-for="(tab, index) in tabs"
:key="index"
:to="tab.path"
:name="tab.name"
:label="$t(tab.label)"
:ripple="false"
exact
@click="onTabClick(tab)"
/>
and then emit the event in a method:
methods: {
onTabClick (tab) {
console.log("this is now called", tab.name)
this.$emit('onTabChange', tab.name)
}
}
英文:
Ok I have solved this by adding the click event on:
<q-route-tab
v-for="(tab, index) in tabs"
:key="index"
:to="tab.path"
:name="tab.name"
:label="$t(tab.label)"
:ripple="false"
exact
@click="onTabClick(tab)"
/>
and then emit the event in a method:
methods: {
onTabClick (tab) {
console.log("this is now called", tab.name)
this.$emit('onTabChange', tab.name)
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论