从计算值中未定义数据变量



我认为我没有正确理解某些东西,或者是一个明显的疏忽,但我无法访问从我的数据()函数返回的值在我的Vue组件的计算属性。从我下面的代码,我试图返回一个计算属性newmessage,但它是说,消息是未定义的,所以是在数据中的一切,如果我尝试。谢谢你的帮助:)

<script>
export default {
props:['alertdata'],
data () {
return {
message: 'hello',
expanded: [],
singleExpand: false,
alertHeaders: [
{
text: 'Rule Number',
align: 'start',
sortable: false,
value: 'RuleNumber',
},

{ text: 'Date', value: 'DateCreated' },
{ text: 'Amount', value: 'Amount' },
],
alerts: this.alertdata,
transactions : this.alertdata.detail,     
}
},
computed: {
newmessage : function() { 
return message.reverse()
}

}
}

</script>

通常,在Vue中的方法、计算属性或生命周期处理程序中,您将使用this来引用方法/计算/处理程序所附加的组件。this是指当前执行函数的上下文。

在您的情况下,您需要在消息

之前添加this
computed: {
newmessage : function() { 
return this.message.reverse()
}

您需要使用this关键字引用data中定义的属性:

newmessage : function() { 
return this.message.reverse()
}

最新更新