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
【Q100】如何使用 react/vue 实现一个 message API #101
Comments
主要实现思路就是创建一个div到body下,然后利用ReactDOM.render将组件渲染到这个容器下,这只是一个简单的实现,没实现关闭和多次调用 |
Vue 实现也是差不多,可以先写好一个 render 函数,作用是把某一HTML片段挂载到 #root 下 / 从 #root 删除该片段。然后写一个 Vue 插件,就是一个暴露了包含 install 方法的模块,install 方法中将 设置 Vue.prototype.$message = message 对象。最后使用 Vue.use 全局注册这个插件即可。 |
|
用createPortal会好点,符合createPortal的使用场景并且如果message复杂点createElement就用不了 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
可以实现如下 API
message.info()
message.success()
The text was updated successfully, but these errors were encountered: