0

I think im not understanding something properly or is an obvious oversight but I cant access values returned from my data() function in my Vue component's computed properties. From my below code i am trying to return a computed property newmessage but it is saying that message is undefined and so is everything else in data if i try. Appreciate any help :)

<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>

2 Answers 2

1

Typically, inside methods, or computed properties or lifecycle handlers in Vue, you will use this to refer the component to which the method/computed/handler is attached. this refers to the context in which the function is currently executing.

in your case you need to add this before message

computed: {
    newmessage : function() { 
    return this.message.reverse()
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Of course haha - Ive been staring at the screen for too long i think! Thank you for your answer.
1

You need to refer to property defined in data with this keyword:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.