Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MarvinXu opened this issue Jul 21, 2017 · 5 comments
Closed

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

MarvinXu opened this issue Jul 21, 2017 · 5 comments

Comments

@MarvinXu
Copy link

MarvinXu commented Jul 21, 2017

问题如下:

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

@Gcaufy
Copy link
Collaborator

Gcaufy commented Jul 21, 2017

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

image
image

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

@MarvinXu
Copy link
Author

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

@Gcaufy
Copy link
Collaborator

Gcaufy commented Jul 21, 2017

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

好的,非常感谢~

@MarvinXu
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants