Skip to content

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

@MarvinXu

Description

@MarvinXu

问题如下:

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

Activity

Gcaufy

Gcaufy commented on Jul 21, 2017

@Gcaufy
Collaborator

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

image
image

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

MarvinXu

MarvinXu commented on Jul 21, 2017

@MarvinXu
Author

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

Gcaufy

Gcaufy commented on Jul 21, 2017

@Gcaufy
Collaborator

工具使用 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

MarvinXu

MarvinXu commented on Jul 21, 2017

@MarvinXu
Author

好的,非常感谢~

MarvinXu

MarvinXu commented on Jul 21, 2017

@MarvinXu
Author

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

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

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

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Gcaufy@MarvinXu

        Issue actions

          computed属性真机上不能实时更新? · Issue #270 · Tencent/wepy