Results 6 comments of Terry Su 苏溪云

> 下面是已经更新后的代码了,但是点开vscode里的debugger,还是之前的代码 多研究下,应该没啥问题

@ihoey 的确,这是摸索许久发现的一个简易方法。可以新建目录结构: ``` models |__ model.js |__ LibraryApp.js(这里就是类vuex的class写法) ``` model.js ``` import LibraryApp from './LibraryApp' export const libraryApp = new LibraryApp() ``` 然后在vue或vuex中直接引用 ```js import { libraryApp } from '../models/model'...

其实它并没有对应vue或vuex的state、getter等,只是一个普通非响应式model对象,参考了vuex的写法,在任何地方都可以引用。如果你要在vuex中使用,直接引入getters或actions使用就行。

我之前尝试过一次封装Vuex为这样的写法,但时间有限,发现有很多问题需要解决,不过redux完全可以。你感兴趣也可以试试写一个vuex的。 另外,也可以参考下现成的[mobx](https://mobx.js.org/getting-started.html), 跟我们这个需求很像。 ![image](https://user-images.githubusercontent.com/23733477/63146430-82153500-c02d-11e9-90ae-0e6fe1a2533f.png)

因为React有一套确保最终更新结果正确的更新机制,可参看:https://github.com/facebook/react/blob/v17.0.1/packages/react-reconciler/src/ReactUpdateQueue.new.js