We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Vue 组件化开发需要用到模态对话框 Modal,捣鼓了半天才成功调用,真是折腾。
上 euvl/vue-js-modal 官网看 README.md 研究组件的正确用法,发现官方文档并不是完全正确的,经过一番折腾,才成功调用组件。
定义 Modal 时,按照如下格式,将代码保存为 VideoModal.vue 文件:
VideoModal.vue
<template> <modal name="video-modal"> <div>This is a modal!</div> </modal> </template> <script> export default { name: 'VideoModal', }; </script>
template 中的 name 属性值要用短横线分隔命名,script 中的 name 属性值则要用驼峰命名。
template
name
script
调用 Modal 时,先在调用该组件的 .vue 文件中的 script 代码块内,以下面的方式引入组件:
import VideoModal from './components/VideoModal'; export default { name: 'App', components: { VideoModal, } };
然后在 template 中,以下面的格式插入组件,即用短横线分隔命名的形式调用:
<video-modal/>
最后,在需要显示/隐藏该组件时,用下面的方式实现:
// 在 script 中 this.$modal.show('video-modal'); // 官方文档也列出了下面这种写法,但是实际应用的时候是无效的 this.$modal.show('VideoModal'); // 在 template 中 <div @click="$modal.hide('video-modal')"></div>
即使是官方文档,也需要“辩证”地看,有时候的确是文档写错了,就需要自己能够找准出现问题的原因。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
需求描述
Vue 组件化开发需要用到模态对话框 Modal,捣鼓了半天才成功调用,真是折腾。
方案调研
调研过程
上 euvl/vue-js-modal 官网看 README.md 研究组件的正确用法,发现官方文档并不是完全正确的,经过一番折腾,才成功调用组件。
应用过程
Modal 定义
定义 Modal 时,按照如下格式,将代码保存为
VideoModal.vue
文件:template
中的name
属性值要用短横线分隔命名,script
中的name
属性值则要用驼峰命名。Modal 调用
调用 Modal 时,先在调用该组件的 .vue 文件中的
script
代码块内,以下面的方式引入组件:然后在
template
中,以下面的格式插入组件,即用短横线分隔命名的形式调用:最后,在需要显示/隐藏该组件时,用下面的方式实现:
要点总结
即使是官方文档,也需要“辩证”地看,有时候的确是文档写错了,就需要自己能够找准出现问题的原因。
The text was updated successfully, but these errors were encountered: