zoukankan      html  css  js  c++  java
  • 微信小程序之开发的坑

    一、前沿

      开发中遇到各种各样的坑,甚是头疼。为了避免在下一次踩到同样的坑,可以把坑都记录下来,毕竟好记性不如烂笔头。

      本文记录的就是博主在小程序开发中遇到的各种各样的坑啦!

    二、各种坑

    1. setData数组使用push的坑(数组操作最好在setData外面)

    2. 引用组件或各种库时,显示的尺寸有问题,比如button的尺寸变小

    3. 有时候新创建项目时,提示未找到app.json中定义的文件。

    三、对应的坑

    1、setData数组使用push的坑(数组操作最好在setData外面)

      代码如下:

    Promise.all(promiseArr).then(res => {
                this.setData({
                  commentlist: this.data.commentlist.push(comment)
                })
                console.log(this.data.commentlist);
              });
    commentlist为数组,使用push后打印出来的是1
    后来改为concat就正常了
    Promise.all(promiseArr).then(res => {
                this.setData({
                  commentlist: this.data.commentlist.concat(comment)
                })
                console.log(this.data.commentlist);
              });

      不只是push有这个问题,splice也有,说不定其他的方法也是这样,为了保证没有错误,建议所有的数组操作都放在setData外边进行处理,如下:

    Promise.all(promiseArr).then(res => {
                this.data.commentlist.push(comment)
                this.setData({
                  commentlist: this.data.commentlist
                })
                console.log(this.data.commentlist);
              });

      这样应该就没有什么问题了。

    2、引用组件或各种库时,显示的尺寸有问题,比如button的尺寸变小

                  

       罪魁祸首是app.json中的style属性,把它去掉就正常了。

    3、有时候新创建项目时,提示未找到app.json中定义的文件。

      

      可以把路径名字加个数字,然后保存就成功了,比如写成category1。

     
  • 相关阅读:
    批处理命令之实现修改环境变量的值
    【hihocoder 1304】搜索一·24点
    【hihocoder 1297】数论四·扩展欧几里德
    【hihocoder 1298】 数论五·欧拉函数
    【hihocoder 1303】模线性方程组
    C语言如何动态分配二维数组
    Istream中的函数
    string 与 char * 转换
    boost 系列 1:boost 直接使用
    glog功能介绍 一分钟 51CTO技术博客
  • 原文地址:https://www.cnblogs.com/interesting-whh/p/13209287.html
Copyright © 2011-2022 走看看