如何在Vuetify中显示Snackbars?
目前,我的Snackbar单击按钮后未显示。我想将Snackbar组件函数传递给我的按钮,该按钮位于add.vue
中。有什么方法可以传递组件函数吗?
snackbar.vue
在组件文件夹
<template>
<div class="text-center ma-2">
<v-snackbar v-model="snackbar" :timeout="timeout" top color="primary">
{{ text }}
<template v-slot:action="{ attrs }">
<v-btn color="pink" text v-bind="attrs" @click="snackbar = false" >
Close
</v-btn>
</template>
</v-snackbar>
</div>
</template>
<script>
export default {
data: () => ({
snackbar: false,
text: 'My timeout is set to 2000.',
timeout: 2000,
})
}
</script>
中
<template class="id">
<base-form title="Add Medical Activities">
<template v-slot:actions>
<SnackBar :snackbar="true"/>
<v-btn
dark
@click="snackbar = true"
>test</v-btn>
</template>
<form-input v-model="inputs" :select-multiple="false"></form-input>
</base-form>
</template>
<script>
import SnackBar from '~/components/SnackBar.vue'
export default {
components: { BaseForm, FormInput, SnackBar },
Currently ,my snackbar is not showing after clicking the button. I want to pass the snackbar component function to my button which located in Add.vue
. Is there any way to pass the component function?
Snackbar.vue
in component folder
<template>
<div class="text-center ma-2">
<v-snackbar v-model="snackbar" :timeout="timeout" top color="primary">
{{ text }}
<template v-slot:action="{ attrs }">
<v-btn color="pink" text v-bind="attrs" @click="snackbar = false" >
Close
</v-btn>
</template>
</v-snackbar>
</div>
</template>
<script>
export default {
data: () => ({
snackbar: false,
text: 'My timeout is set to 2000.',
timeout: 2000,
})
}
</script>
Add.vue
file
<template class="id">
<base-form title="Add Medical Activities">
<template v-slot:actions>
<SnackBar :snackbar="true"/>
<v-btn
dark
@click="snackbar = true"
>test</v-btn>
</template>
<form-input v-model="inputs" :select-multiple="false"></form-input>
</base-form>
</template>
<script>
import SnackBar from '~/components/SnackBar.vue'
export default {
components: { BaseForm, FormInput, SnackBar },
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需要在V模型上传递
任何使更改
snackbar
true的操作传递,Snackbar将像您期望的那样打开它you only need boolean passed on your v-model
any operation that make change
snackbar
to true, snackbar will open it like what you expected尝试一下:
add.v
snackbar.vue
我希望这对您有帮助。
Try this out:
Add.v
Snackbar.vue
I hope this helps you.