0

How can I translate this :

var start = Date.now();
var end = Date.now() + 604800000;

to vue.js? Is it in methods? actions?

Is something like this correct?

actions: {
    start ({commit, getters}, payload) {
        var start = Date.now()
    },
1
  • 1
    vue.js is javascript. Technically no 'translation' required. It really depends on what you're trying to accomplish. Maybe tell us more about your problem? Commented Nov 3, 2018 at 17:06

1 Answer 1

1

Do you want to use vuejs or Vuex? actions is a reserved to register actions on a Vuex store. You can find below how to translate your code in a simple Vue instance.

index.html

<body>
  <div id="app"></div>
</body>

main.js

import Vue from "vue";

new Vue({
  el: "#app",
  template: "<p> {{ end }}</p>",
  data: {
    start: null
  },
  mounted() {
    this.start = Date.now();
  },
  computed: {
    end() {
      return this.start + 604800000;
    }
  }
});

For this example, start is calculated when the vue instance is mounted on the <div id="app"></div> block. end is a computed property that will be calculated as soon as the start property value has changed.

Have a look at here, they describe a similar example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.