0

Within a Vue component, I am calling a function from a separate JS file. I then need to call a method in my component just after this first function is completed:

My .vue component:

import myFunction from '@/components/functions';

export default {
  name: 'test',
  components: {
    myFunction,
  },      
  created(){
    if (....) {      
      myFunction.function1(myParam)          
        .then((response) => {
        this.method2();
       });         
  },  
  methods:{
    method2(){
      something;     
    },
  }
};

My separate functions.js file:

export default {
  function1(myParam) {
    ...
    return true;
  },
};

I tried several things such as the last one shown in my code which gives me a

.function1(...).then is not a function

I am sure it is not that complicated but can not find the correct syntax.

1 Answer 1

1

The function in your other file could return a Promise or it can except a callback from your view component. Also, if you set this equal to self/vm and then use vm.method2(), this is because in the then callback this is defined in scope of that function not the Vue component.

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.