-
-
Notifications
You must be signed in to change notification settings - Fork 930
支持直接传入元素进行初始化 #231
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
Comments
使用了 ID 会有什么影响么? |
API设计应遵循最少知识原则 ID作为必填参数我看好像只是实现了可选的缓存功能 有什么影响我上面不都说了
ID要是没啥其它我不知道的用处我可以PR |
我现在实际用例是 |
你有空的话就提 PR 吧,现在忙着弄 ir 模式中的 toolbar。 PS: 如果有传入 id, cache 还是用 id 标识,这样就应该可以兼容以前的用户了。 |
Merged
stevapple
pushed a commit
to stevapple/vditor
that referenced
this issue
Apr 8, 2020
stevapple
pushed a commit
to stevapple/vditor
that referenced
this issue
Apr 8, 2020
stevapple
pushed a commit
to stevapple/vditor
that referenced
this issue
Apr 8, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
你在什么场景下需要该功能?
现在初始化需要元素id, 然后所有操作都基于
document.getElementById(vditor.id)
但是元素的ID值是可写的, 还有ID重复的可能
应该在初始化时直接保存Element引用,这样就可以避免对ID的依赖。
描述可能的解决方案
new Vditor
的首个参数改为string | HTMLDivElement
传入 string 时匹配当前行为,传入 Element 时直接使用。
内部使用初始化时获取到的 element 而不是使用
document.getElementById
options 的
cache
参数改为boolean | string
来指定 localStorage 的 key。为 true 时要求 id 为 string,匹配当前行为。
其他信息
我作为 Vue 组件用,并且不使用缓存想避免 id 作为必填属性。
所以都是每次初始化生成一个ID 初始化完了再去掉, 并从工具栏里面移除所有使用了
document.getElementById
的功能The text was updated successfully, but these errors were encountered: