Javascript vue属性装饰器:道具正在变异?
我使用的是Javascript vue属性装饰器:道具正在变异?,javascript,vue.js,Javascript,Vue.js,我使用的是vue属性装饰器,它是一个简单的组件,我收到了错误消息: [Vue warn]: 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: "messag
vue属性装饰器
,它是一个简单的组件,我收到了错误消息:
[Vue warn]: 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: "message"
这个消息意味着什么?我怎样才能解决这个问题
以下是我的代码示例:
<template>
<v-layout row justify-center>
<v-dialog v-model="dialog">........</v-dialog>
</v-layout>
</template>
<script lang="ts">
import { Component, Prop } from 'vue-property-decorator';
@Component({})
export default class SomeModal extends ... {
@Prop() public dialog?: boolean;
@Prop() public message?: string;
constructor() {
super();
}
public showError(er) {
this.message = er.message;
this.dialog = true;
}
}
</script>
<style scoped lang="scss">
</style>
........
从“vue属性装饰器”导入{Component,Prop};
@组件({})
导出默认类SomeModal扩展。。。{
@Prop()公共对话框?:布尔值;
@Prop()公共消息?:字符串;
构造函数(){
超级();
}
公共淋浴器(er){
this.message=er.message;
this.dialog=true;
}
}
对于vue,我没有使用这种语法,但信息非常清楚:您需要定义数据属性或计算变量。这意味着:
data: {
dialogData: ''
}
constructor() {
super();
this.dialogData = this.dialog;
}
或:
有关计算属性,请参阅vuejs文档
编辑:使用vue属性装饰器,它可以是:
@Component
export default class YourComponent extends Vue {
// your code here...
private _dialogData: string = '';
constructor() {
super();
this._dialogData = this.dialog;
}
}
@Component
export default class YourComponent extends Vue {
// your code here...
private _dialogData: string = '';
constructor() {
super();
this._dialogData = this.dialog;
}
}