小程序进阶学习03

  • 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调用):地址
发布了114 篇原创文章 · 获赞 32 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/moqianmoqian/article/details/104546576
今日推荐