"; 2. In the vue component, pass "import from ' js file path'"."/> "; 2. In the vue component, pass "import from ' js file path'".">
Home >Web Front-end >JS Tutorial >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.
<!DOCTYPE html> <html> <head> <title>Map</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <link rel="shortcut icon" type="image/x-icon" href="./static/img/favicon.ico"/> <script src='./static/libs/three/three.min.js'></script> <script src="./static/libs/three/GLTFLoader.js"></script> </head> <body> <p id="app"></p> <!-- built files will be auto injected --> </body></html>
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!