微信小程序开发 -- 踩坑

    xiaoxiao2021-03-26  27

    自学微信小程序,用小程序做了个小项目,踩了一些坑:

    坑一:

    Navigated to http://1755603039.appservice.open.weixin.qq.com/appservice VM2507:1 Sat Feb 04 2017 21:46:27 GMT+0800 (中国标准时间) 渲染层错误 VM2507:2 SyntaxError: Invalid or unexpected token (anonymous) @ VM2507:2 VM2509:1 Sat Feb 04 2017 21:46:27 GMT+0800 (中国标准时间) 渲染层错误 VM2509:2 webviewScriptError Invalid or unexpected token SyntaxError: Invalid or unexpected token (anonymous) @ VM2509:2 VM2510:1 Sat Feb 04 2017 21:46:27 GMT+0800 (中国标准时间) 渲染层错误 VM2510:2 Uncaught SyntaxError: Invalid or unexpected token (anonymous) @ VM2510:2 VM2511:1 Sat Feb 04 2017 21:46:27 GMT+0800 (中国标准时间) 渲染层错误 VM2511:2 ReferenceError: $gwx is not defined at 1755603039.debug.open.weixin.qq.com/pages/index/index.html:1438 (anonymous) @ VM2511:2 VM2512:1 Sat Feb 04 2017 21:46:27 GMT+0800 (中国标准时间) 渲染层错误 VM2512:2 webviewScriptError $gwx is not defined ReferenceError: $gwx is not defined at http://1755603039.debug.open.weixin.qq.com/pages/index/index.html:1438:27 (anonymous) @ VM2512:2 VM2513:1 Sat Feb 04 2017 21:46:27 GMT+0800 (中国标准时间) 渲染层错误 VM2513:2 Uncaught ReferenceError: $gwx is not defined

    出现 $gwx is not defined

    提示报错位置 at http://1755603039.debug.open.weixin.qq.com/pages/index/index.html:1438:27

    这个报错位置提示没有任何意义,因为index.whtml我好几天没有动过了;

    这个错误后来发现  在刚改过的whtml 页面 想写"¥{{user.salary}}/时 "   结果写成了"${{user.salary}}/时" , 将 ¥ 写成了$;

    坑二

    封装了一下微信提供的网络访问接口,结果服务器端死活获取不到传递的参数,最后上网一查,post请求的header必须将content-type设置为 'application/x-www-form-urlencoded',否则后台就接收不到数据,而我设置的是'application/json' ,没有其它原因,因为我就是想传递json数据啊,另外POST必须要大写,这点接口文档上写了,正确代码如下:

    function request(param) { var obj ={ url: param.url, header: { 'content-type': 'application/x-www-form-urlencoded', /****注意:post方式必须这样设置,否则后台获取不到参数 */ /***'content-type': 'application/json',**/ }, method:'POST',/***注意post必须大写 */ data:param.data==undefined ? "":param.data, success: function( res ) { /**console.log(res.data); */ if(param.success && typeof(param.success) =="function" ){ param.success(res); } }, fail: function( res ) { if(param.fail && typeof(param.fail) =="function" ){ param.fail(res); } } } if(app.globalData.token){ obj.header.access=app.globalData.token; } /** console.log( obj.url) console.log(JSON.stringify(obj.data) ); */ wx.request(obj); }

    转载请注明原文地址: https://ju.6miu.com/read-658928.html

    最新回复(0)