vue.jsvuejs2vue-mixin

How to use Mixin in main.js in Vuejs?


I am trying to use global information from a mixin. I intend to access the getNow computed prop in a component, but it seems to be undefined.

main.js:

Vue.mixin({
    data: function() {
        return {
          chainBoxURL: "http://172.22.220.197:18004/jsonrpc"
        }
    },
    computed: {
        getNow() {
          const today = new Date();
          const date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
          const time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
          const dateTime = date + ' ' + time;
          return dateTime;
        }
    }
})

Component:

methods: {
    getChainAddress(form) {
        if (form.password == form.password_again && form.password != '') {
            console.log(this.getNoW)
        }
    }
}

Solution

  • The computed prop in the mixin is defined as: getNow() but youn spelt it as getNoW() within the component.

    Either that or you may have forgot to include the mixin in the component.