Home > Web Front-end > Vue.js > How to introduce external js in vue.js

How to introduce external js in vue.js

coldplay.xixi
Release: 2023-01-13 00:44:45
Original
13934 people have browsed it

How to introduce external js into vue.js: 1. Add code [function formatXml(text){return text}] in the external file [config.js]; 2. Use the import statement to introduce [config.js 】The constants and methods inside are enough.

How to introduce external js in vue.js

The operating environment of this tutorial: Windows 7 system, Vue version 2.9.6, Dell G3 computer. This method is suitable for all brands of computers.

[Related free article recommendations: vue.js]

vue.js method of introducing external js:

1. External file config.js

First way of writing

//常量的定义
 
const config = {
 baseurl:‘http://172.16.114.5:8088/MGT2‘
 }
//函数的定义
function formatXml(text) {
  return text
 }
//导出 {常量名、函数名}
export {config,formatXml}
Copy after login

Second way of writing

//常量的定义
export const config = {
   baseurl:‘http://172.16.114.5:8088/MGT2‘
}
 //函数的定义
 
 export function formatXml(text) {
 return text
}
Copy after login

2.Introduction of config Constants and methods in .js

  import {config,formatXml} from ‘../config‘//记得带上{}花括号
Copy after login

Related free learning recommendations: javascript (video)

The above is the detailed content of How to introduce external js in vue.js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template