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

How to introduce external js in vue.js

coldplay.xixi
coldplay.xixiOriginal
2020-12-03 11:45:1813925browse

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}

Second way of writing

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

2.Introduction of config Constants and methods in .js

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

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!

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 is elementUI in vueNext article:What is elementUI in vue