SoFunction
Updated on 2025-04-12

Two methods of importing vue into js (example details)

1 Method 1: Use tags

Then,In component methods,You can call it directly JavaScript Functions defined in the file:
export default {
  methods: {
    yourMethod() {
      yourFunction1();
      yourFunction2();
      yourFunction3();
    }
  }
}

2 Method 2: Use the import statement

exist Vue Component JavaScript In the file,use import Statement introduction JavaScript In the file的函数:
import { yourFunction1, yourFunction2, yourFunction3 } from './';
Then,existComponent方法中,You can call the imported function directly:
export default {
  methods: {
    yourMethod() {
      yourFunction1();
      yourFunction2();
      yourFunction3();
    }
  }
}

3 Examples

3.1 js file

// 
export function function1() {
  // Logic of function 1}
export function function2() {
  // Logic of function 2}
export function function3() {
  // Logic of function 3}

3.2 Vue import js file

// 
import * as functions from './';
export default {
  methods: {
    yourMethod() {
      functions.function1();
      functions.function2();
      functions.function3();
    }
  }
}

4 Examples

4.1 js file

// 
function function1() {
  // Logic of function 1}
function function2() {
  // Logic of function 2}
function function3() {
  // Logic of function 3}
export default {
  function1,
  function2,
  function3
}

4.2 vue import js file -->XXX is a custom variable name

import XXX from './';
export default {
  methods: {
    yourMethod() {
      XXX.function1();
      XXX.function2();
      XXX.function3();
    }
  }
}

5. After modifying the file, be sure to save it and run it

This is the end of this article about the method of importing vue into js. For more related vue to import js content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!