Home  >  Article  >  Web Front-end  >  Introducing external js method instances into vue

Introducing external js method instances into vue

小云云
小云云Original
2018-03-02 11:24:247256browse

When we are working on vue projects, we often need to introduce js. The following are commonly used. This article mainly shares with you examples of introducing external js methods into vue, hoping to help everyone.

The first one

import XX from “路径”
Vue.use(XX);
这里的js文件要导出
用export default {
Vue.proprtypes.aa=function(){}
}

The second one

js file does not use export default{}

It’s just a pure method

Solution : You can add the following code to main.js, and the methods in it can be used globally.

require ('path')

The third method

is also a pure method

At the end, use export default {} for the method you want to use. Export

This method is used in a single Vue file, introduce your method through import {xxx} from 'path'

When using it, just call xxx.

When we are working on vue projects, we often need to introduce js. The following are commonly used.

The first one

import XX from “路径”
Vue.use(XX);
这里的js文件要导出
用export default {
Vue.proprtypes.aa=function(){}
}

The second one

js file does not use export default{}

It’s just a pure method

Solution : You can add the following code to main.js, and the methods in it can be used globally.

require ('path')

The third method

is also a pure method

At the end, use export default {} for the method you want to use. Export

This method is used in a single Vue file, introduce your method through import {xxx} from 'path'

When using it, just call xxx.

Related recommendations:

How does the JS loader dynamically load external js files

Introduce external js files into html and call the Methods of parameterizing functions

Referring to external js garbled problem analysis and solutions_javascript skills

The above is the detailed content of Introducing external js method instances into vue. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn