V
V
vetsmen2018-03-05 16:35:31
Vue.js
vetsmen, 2018-03-05 16:35:31

How to pass parameter to cumputed Vue.js?

Task: you need to attach your own timer for the reverse time for each element. Each element has its own time.
What I do: I created a setInterval that pushes the current time to the variable every second.
Created 2 computed properties:

getMinutes: function (time) {
        	return Math.trunc((time - this.now) / 1000 / 60) % 60;
        },
        getSeconds: function (time) {
        	return ((time - this.now) / 1000) % 60;
        }

And I call them like this:
{{ getMinutes(item.offer_timestamp) }} : {{ getSeconds(item.offer_timestamp) }}

However, he writes that t.getMinutes is not a function.
Tried the same in watch, similar situation.
As I understand it, neither through cumputed nor through watch it is possible to forward a variable. How to be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly Zharov, 2018-03-05
@vetsmen

Use filter instead of computed
https://ru.vuejs.org/v2/guide/filters.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question