chameleon 快应用:在 app.cml 中更新 store.state 在其他组件内不生效

6qftjkof  于 2022-10-20  发布在  其他
关注(0)|答案(1)|浏览(146)

bug描述

快应用在 app.cml 中更新 store.state 在其他组件内不生效

复现bug的步骤

  1. clone 官方 demo 仓库 https://github.com/beatles-chameleon/cml-demo/tree/master-quickapp
  2. git checkout master-quickapp & yarn & cml quickapp dev
  3. 在 app.cml 中更新 store 状态,我是在 beforeMount 中
    store.state.index.name 默认是李四,这里改成了 cml
beforeMount() {
   console.log(store.state.index.name) // 李四
   store.commit('INDEX_CHANGE_NAME', 'cml')
   console.log(store.state.index.name) // cml
 }
  1. 在 index.cml 引入 store, 并引入状态
import store from '../../store/index'
...
computed = {
    name() {
      return store.state.index.name
    }
  }
...
mounted() {
    console.log(this.name)
  }

会看到这里的 name 仍然是李四
5. 在 node_modules/cml-quickapp-store/src/platform/common/mini/index.js(应该是这个文件) 里的 createStore 方法打了 log,发现这个函数执行了两次,猜想是不是创建了两个不同的 store

export default function createStore(...args) {
  console.log(111, 'createStore')
  return new Store(...args)
}

问题截图

编译环境信息

  • chameleon-tool 版本:chameleon-tool@1.0.3
  • nodejs版本、npm版本:[node v11.9.0、npm 6.5.0]
  • 电脑操作系统: [macOS Mojave 10.14.4]

运行环境信息

  • 端版本:快应用开发工具 1.5.3
d6kp6zgx

d6kp6zgx1#

�快应用对于store的实现未到100%,我们还在继续完善中,敬请期待

相关问题