"; 2. In the vue component, pass "import from ' js file path'"."/> "; 2. In the vue component, pass "import from ' js file path'".">

Home  >  Article  >  Web Front-end  >  What are the ways to introduce js files in vue

What are the ways to introduce js files in vue

清浅
清浅Original
2019-05-05 13:21:4839487browse

What are the ways to introduce js files in vue

Several methods of introducing JS files into VUE projects

When developing Vue projects, sometimes you need to use Some non-ES6 format js libraries without export can be implemented in the following ways:

1. Use the script tag on the index.html page to introduce

. Of course, you can also use The address of the cdn. The content imported in this way is global and can be used everywhere.


 

      Map
      
      
      
      
      
   
   
     

2. Use window.moduleName in main.js. Use

or put it into Vue.prototype, so that it can be used in the component.

var THREE = window.THREEvar GLTFLoader = THREE.GLTFLoader
Vue.prototype.THREE = THREE

3. Manually add export

Put export default { /**Method to export**/} for the methods that need to be used in the js library, and then import {*} from Use

in the JS library:

function realconsole(){  
    alert("hello world!");  }  
 export {  
     realconsole }

In the components that need to use the JS library:

import realconsole from './xxx'

4. Use the import method to add the required The method in the js library is mounted to the global

as follows:

 import '@static/libs/GLTFLoader' 
 // 可以从全局获取导入的方法 
 let GLTFLoader = THREE.GLTFLoader

Related recommendations:

2020 front-end vue Summary of interview questions (with answers)

vue tutorial recommendation: 2020’s latest 5 vue.js video tutorial selections

More For programming-related knowledge, please visit: Introduction to Programming! !

The above is the detailed content of What are the ways to introduce js files in 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
Previous article:What can javascript do?Next article:What can javascript do?