N
N
nionly_quantum2020-07-28 20:26:30
Vue.js
nionly_quantum, 2020-07-28 20:26:30

Vue js How to validate by user id and display exactly his product?

I want to display the user's purchase history and product in my account.
I take the ID from the address bar, example: domain.ru/profile/1
I tried it this way:

async beforeRouteProducts (to, from, next) { try {
  const { data } = await axios.get(`/api/v1/companies/${this.$route.params.id}`)
  next(vm => { vm.products = data })
} catch (e) {
  next(vm => { vm.error = e.response.data })
} },

It doesn't work, I haven't found a solution yet (
Output of the product itself:
<div class="card-carousel--card" v-for="product, index in products">
                  <router-link :to="{ name: 'product', params:{id:product.id}}">
                  <img :src="product.img_index"/>
                  <div class="card-carousel--card--footer">
                    <p>{{ product.name }}</p>
                    <p class="tag" v-for="(tag,index) in product.price" :class="index &gt; 0 ? 'secondary' : ''">{{ tag }}</p>
                  </div></router-link>
                </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2020-07-29
@Nolan81

What about beforeRouteProducts? Did you mean beforeRouteEnter?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question