Skip to content

How to randomly render products after get API to obtain data in Vue? [closed]

this.$http.get(api).then(response => {
        vm.products =;

If i have data about products and i want to randomly render products what should i do?


You can set a computed property where you shuffle your products list, something like this:

computed {
  shufflesProducts() {
    return vm.products.sort(() => Math.random() - 0.5);