"; 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
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!