【发布时间】:2020-10-29 14:31:33
【问题描述】:
我使用snackbar 在vuejs 中显示成功消息。我想做一个全局自定义的snackbar组件。
<template>
<div name="snackbars">
<v-snackbar
v-model="snackbar"
:color="color"
:timeout="timeout"
:top="'top'"
>
{{ text }}
<template v-slot:action="{ attrs }">
<v-btn dark text v-bind="attrs" @click="snackbar = false">
Close
</v-btn>
</template>
</v-snackbar>
</div>
</template>
<script>
export default {
props: {
snackbar: {
type: Boolean,
required: true,
},
color: {
type: String,
required: false,
default: "success",
},
timeout: {
type: Number,
required: false,
default: 3000,
},
text: {
type: String,
required: true,
},
},
};
</script>
然后我将它作为一个组件导入到我的每个表单中。
<SnackBar :snackbar="snackbar" :color="color" :text="text" />
但我的问题是我不能在我的子组件中使用snackbar 作为道具。它显示了这个错误。
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "snackbar"
我该如何解决这个问题。谁能帮帮我?
【问题讨论】:
-
您的错误状态不在道具上使用 v-model。只需使用计算代理它并向父级发送更新
标签: vue.js vuetify.js