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'//記得帶上{}花括號
