Vue.js 引入外部js方法

1、外部文件config.js

第一种写法

 1 //常量的定义
 2 
 3 const config = {
 4   baseurl:'http://172.16.114.5:8088/MGT2'
 5 }
 6 
 7 //函数的定义
 8 
 9 function formatXml(text) {
10   return text
11 }
12 
13 //导出 {常量名、函数名}
14 export {config,formatXml}

第二种写法

 1 //常量的定义
 2 
 3 export const config = {
 4   baseurl:'http://172.16.114.5:8088/MGT2'
 5 }
 6 
 7 //函数的定义
 8 
 9 export function formatXml(text) {
10   return text
11 }

2、引入config.js里面的常量和方法

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

转至:https://www.cnblogs.com/qiu-Ann/p/7463484.html

原文地址:https://www.cnblogs.com/lgjava/p/12762591.html