小程序小程序实例 | 编写请求方法request的方法方法: import {config} from '../config.js' const tips={ 1:'默认错误', 1005:'appkey错误', 1007: '网址错误', 3000:'该期内容不存在' } class HTTP{ request(params){ if (!params.method){ params.method='GET'作者王明昌发布时间2018-08-05 方法: 复制import {config} from '../config.js' const tips={ 1:'默认错误', 1005:'appkey错误', 1007: '网址错误', 3000:'该期内容不存在' } class HTTP{ request(params){ if (!params.method){ params.method='GET' } wx.request({ url: config.api_base_url+params.url, method:params.method, data:params.data, header:{ 'content-type':'application/json', 'appkey':config.appkey }, success:(res)=>{ let code = res.statusCode.toString() console.log(code) //es6 新 startsWith 以什么开头 endWith 以什么结尾 if(code.startsWith('2')){ params.success(res.data); }else{ // wx.showToast({ // title: '错误', // icon:'none', // duration:1500 // }) let error_code = res.data.error_code this._show_error(error_code) } }, fail:(err)=>{ // wx.showToast({ // title: '错误', // icon: 'none', // duration: 1500 // }) this._show_error(1) } }) } _show_error(error_code){ if(!error_code){ error_code=1 } console.log(error_code) wx.showToast({ title:tips[error_code], icon: 'none', duration: 1500, }) } } export {HTTP}; 使用: 复制引用并实例化 import {HTTP} from '../../util/http.js'; let http = new HTTP() 使用 http.request({ url:'classic/latest', success:(res)=>{ console.log(res) } })
2018-12-09小程序 | 在首页判断是否登录并跳转到登陆界面login //index.js import { config } from '../../config.js' Page({ /** * 页面的初始数据 */ data: { //判断小程序的AP
2019-07-22小程序判断是否包含某个字符(数组和字符串)console.log(['x', 'a'].indexOf('a')); // 1 console.log('dbac'.indexOf('aa')); // -1
2018-12-09小程序 | 在首页判断是否登录并登陆执行index.wxml //其他业务 我知道了 index.js import { config } from '../../config.js' // pages/index/index.js Pag
2018-10-07小程序组件 | mask遮罩层组件定义组件 wxml: wxss .container{ background-color: #000; position: fixed; top: 0; opacity: 0.6; width: 10
2018-12-09微信小程序 form表单input变化时自动搜索index.wxml 搜索 取消 index.js inputTyping: function (e) { var title = e.detail.value; console.log(e) //
2018-12-09小程序 | 小程序中使用关注公众号功能实现在小程序中显示公众号,点击后进行关注 使用组件 使用说明 使用组件前,需前往小程序后台,在“设置”->“接口设置”->“公众号关注组件”中设置要展示的公众号。 注:设置的公众号需与小程序主体一致。