Tencent / wepy

小程序组件化开发框架

Home Page:https://wepyjs.gitee.io/wepy-docs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

computed属性真机上不能实时更新?

MarvinXu opened this issue · comments

问题如下:

data = {
  storage: [
    {
      id: 1,
      name: '库位1',
      size: 2,
      store: []
    },
    {
      id: 2,
      name: '库位2',
      size: 20,
      store: []
    },
    {
      id: 3,
      name: '库位3',
      size: 10,
      store: []
    }
  ],
  storageIndex: 0
}

computed = {
  curStore () {
    return this.storage[this.storageIndex]
  }
}

当我往store中push值时

this.storage[this.storageIndex].store.push(...this.scanResults)

以下computed属性不更新(开发者工具正常,真机不行)

<text class="desc">库存:{{curStore.store.length}}/{{curStore.size}}</text>

https://github.com/MarvinXu/zj-tool/blob/master/src/pages/stock-in.wpy


另外写了一个test,也有同样的问题
https://github.com/MarvinXu/zj-tool/blob/master/src/pages/test.wpy

刚用你的代码真机测试了一下,是“开启代码压缩”的问题,如下图:

image
image

所以,关闭代码压缩就好了。

为什么会跟压缩有关系呢,难道发布的代码也不压缩么?

工具使用 babili 压缩,不知道什么原因,导致代码失效,这个有时间的时候我再去研究一下。
开发的时候完全不必要压缩,发布的时候压缩是通过插件去做的,与webpack使用习惯一样,代码是通过wepy-plugin-uglifyjs压缩的。
我习惯在 package.json中配置两个命令:


  "scripts": {
    "build": "cross-env NODE_ENV=production wepy build --no-cache",
    "watch": "wepy build --watch --no-cache"
  },

开发时使用npm run watch,发布时使用npm run build

好的,非常感谢~

分享一段小插曲。
我在验证是不是“开启代码压缩”的问题的时候,本地突然复现不了了!无论是否开启压缩,真机上都正常!

我又重新clone项目重新安装依赖,复现了。。

对比文件发现,dist下的npm/wepy/lib的代码没被压缩,而之前的项目是压缩的。

因为我在期间运行了一次npm run build,而之后再npm run dev,dist下的npm不会被更新,依然是之前压缩的版本。所以无论开发工具是否压缩都正常~

综上看来,确实是开发工具压缩wepy源码的时候出的问题。