Several ways to introduce JS files in VUE project
When developing Vue projects, you sometimes need to use some non-ES6 format js libraries without export. You can implement it in the following ways:
1. Use script tags to import on the page
Of course, you can also use the CDN address. The content introduced in this way is global and can be used everywhere.
<!DOCTYPE html> <html lang=zh-CN> <head> <meta charset=utf-8> <meta http-equiv=X-UA-Compatible content="IE=edge"> <meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover"> <title>Online contract signing inquiry</title> <link rel=stylesheet href=./static/index.> **IntroducedJS** <script src=/jmopen/jssdk/ charset=utf-8></script> </head> <body> <div id=app></div> <script src=./static/js/chunk-vendors.></script> <script src=./static/js/index.></script> </body> </html>
2. Use in
It can also be placed in the component so that it can be used.
var THREE = GLTFLoader = = THREE
3. Add export manually
Put export default { /Methods to export/}, then use via import {*} from
In the JS library:
function realconsole(){ alert("hello world!"); } export { realconsole }
In components that require using the JS library:
import realconsole from './xxx'
4. Use the import method to mount the required methods in the js library to the global
import '@static/libs/GLTFLoader' // You can get imported methods from the globallet GLTFLoader =
Out of the question: If we need to call the method of the vue page in the called JS file method, we can perform the following operations
Calling methods in vue in js
Register the method on the vue page to the window object, and then call it directly on the js page
mounted() { = }, methods: { functionForJs(data) { ('Receive parameters', data) } }
export function doSomething() { ('Hahaha') }
Summarize
This is the article about vue citing external JS and calling methods in JS files. For more related vue citing external JS content, please search for my previous articles or continue browsing the following related articles. I hope everyone will support me in the future!