0

Code for vue component:

        data() {
            return {
                patrons : {},
              }
            },
            methods: {
              loadPatron(){
                   axios.get("api/patron")
                       .then(({data}) => (this.patrons= data.data));


              //Count records
              console.log(this.patrons.length); //This line of code does not seem to work.
              },
            }

How do we count the records and display them in the console.log?

0

1 Answer 1

2

You have to place console.log either inside axios get function after assignment

axios.get("api/patron")
   .then(({data}) => {
      this.patrons = data.data
      console.log(this.patrons);
   });

or create watcher for patrons property and console.log there

watch: {
   patrons: {
     handler: function() {
       console.log(this.patrons)
     },
     deep: true
   }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, I'm new. How do I do this? If you have time can you show the code. Thank you.

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.