1、外部文件config.js
第一種寫法
//常量的定義
const config = {
baseurl:'http://172.16.114.5:8088/MGT2'
}
//函數的定義
function formatXml(text) {
return text
}
function getjs1() {
return "11223344"
}
//導出 {常量名、函數名}
export {config1,formatXml,getjs1}
第二種寫法
//常量的定義
export const config = {
baseurl:'http://172.16.114.5:8088/MGT2'
}
//函數的定義
export function formatXml(text) {
return text
}
2、引入config.js里面的常量和方法
import {config,formatXml} from '../config'//記得帶上{}花括號
import {getjs1} from "./config"
3、調用
getjs1()