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

记一次前端项目重构要点总结 #7

Open
Terry-Su opened this issue Jul 4, 2019 · 8 comments
Open

记一次前端项目重构要点总结 #7

Terry-Su opened this issue Jul 4, 2019 · 8 comments

Comments

@Terry-Su
Copy link
Owner

Terry-Su commented Jul 4, 2019

No description provided.

@ihoey
Copy link

ihoey commented Aug 15, 2019

非常想学习下
三、解耦可视化库和Vue/Vuex

想学习下完整的使用方法, 感觉这样写很不错唉

@Terry-Su
Copy link
Owner Author

@ihoey 的确,这是摸索许久发现的一个简易方法。可以新建目录结构:

models
|__  model.js
|__  LibraryApp.js(这里就是类vuex的class写法)

model.js

import LibraryApp from './LibraryApp'
export const libraryApp = new LibraryApp()

然后在vue或vuex中直接引用

import { libraryApp } from '../models/model'
export default {
  ...
  mounted() { libraryApp.render()  }
  ...
}
...

@ihoey
Copy link

ihoey commented Aug 16, 2019

还是比较好奇 class 写法是怎么对应上如 State Getter 的呢 如果直接在 vue 里面用的话 就相当于没有用 vuex

@Terry-Su
Copy link
Owner Author

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

@ihoey
Copy link

ihoey commented Aug 16, 2019

明白了, 也就是这样的写法其实没有办法直接用在 vuex 对吧 还是要将 getters actions 等单独写,刚开始没有看懂 类vuex 的意思😅😅

@Terry-Su
Copy link
Owner Author

我之前尝试过一次封装Vuex为这样的写法,但时间有限,发现有很多问题需要解决,不过redux完全可以。你感兴趣也可以试试写一个vuex的。
另外,也可以参考下现成的mobx, 跟我们这个需求很像。
image

@ihoey
Copy link

ihoey commented Aug 16, 2019

好的 非常感谢 之前没有用过 mobx 我去看下

@DESERTFOXKING
Copy link

使用Map代替判断更占用内存

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

3 participants