[Vuejs]-Vue – how to show an array of data in a table?

3πŸ‘

βœ…

Blockquote

You can use life-cycle hook mounted to fetch data on initial page load.

export default {
  data() {
    return {
      balances: [],
    }
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      fetch('http://127.0.0.1:8000/binance/getbalance')
        .then(response => response.json())
        .then(data => {
          this.balances = data
        })
    }
  }
}

you can also use created to fetch data on initial page created is executed before mounted for reference enter link description here e.g.

export default {
  data() {
    return {
      balances: [],
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      fetch('http://127.0.0.1:8000/binance/getbalance')
        .then(response => response.json())
        .then(data => {
          this.balances = data
        })
    }
  }
}
πŸ‘€Nilesh Patel

0πŸ‘

You are doing it wrong, you’re not using vue correctly:

<script>



export default {
    created() {

      fetch('http://127.0.0.1:8000/binance/getbalance')
       .then(response => response.json())
       .then(data => {
         this.balances = data
        
       })
    },
    data () {
      return {
        balances: [],
      }
    },
}

</script>
πŸ‘€Tomer

Leave a comment