- 1 模板字符串
//反引号包裹,将表达式和字符串传给默认函数,由其进行连接
`${config.apiBaseUrl}theme/by/names`
- 2 分离固定文件到配置文件
config/config.js
const config = {
appkey:'',
apiBaseUrl:''
};
//es6导出
export {
config
}
其他js使用
//导入
import {config} from "../../config/config";
......
url:`${config.apiBaseUrl}theme/by/names`,
......
- 3 小程序post和get请求时data作用不同
//get请求:相当于 url:'http://se.sleeve.7yue.pro/v1/theme/by/names?names=t-1',
url:'http://se.sleeve.7yue.pro/v1/theme/by/names',
method:'GET',
//若采用post方法,data将被视为body
data:{
names:'t-1'
}
- 4 搭建mock server(模拟api调用):地址