此指令在处理 QDialog 和 QMenu 组件时会有所帮助。当附加到 DOM 元素或组件时,该组件在被点击/轻触时将关闭 QDialog 或 QMenu(以第一个父级为准)。
¥This directive is a helper when dealing with QDialog and QMenu components. When attached to a DOM element or component then that component will close the QDialog or QMenu (whichever is first parent) when clicked/tapped.
用法(Usage)
¥Usage
基本(Basic)
¥Basic
关闭多个层级(Closing multiple levels)
¥Closing multiple levels
你还可以通过为指令提供级别编号来关闭多级弹出窗口:
¥You can also close multiple levels of popups by supplying a level number to the directive:
<... v-close-popup="3">
如果值为 0 或布尔值
false
,则指令被禁用¥If value is 0 or boolean
false
then directive is disabled如果值小于 0,则关闭链中的所有弹出窗口
¥If value is < 0 then it closes all popups in the chain
如果值为 1 或布尔值
true
或未定义,则仅关闭父级弹出窗口¥If value is 1 or boolean
true
or undefined then it closes only the parent popup如果值大于 1,则关闭链中指定数量的父级弹出窗口(请注意,链接的 QMenus 仅被视为一个弹出窗口,并且 QPopupProxy 会分隔链接的菜单)
¥If value is > 1 it closes the specified number of parent popups in the chain (note that chained QMenus are considered 1 popup only & QPopupProxy separates chained menus)
请注意,下面的链接 QMenus(一个直接放在另一个下方)不需要指定多个级别。当 v-close-popup
用于链接的 QMenu 时,它会将所有直接链接的 QMenus 视为同一层级。
¥Notice below that chained QMenus (one directly put under the other) do not require you to specify multiple levels. When v-close-popup
is used in a chained QMenu, it considers all directly chained QMenus as one level only.
在以下示例中,菜单使用两级,这意味着它也会关闭对话框,因为对话框是其父级:
¥In the example below, the menu uses 2 levels, which means it will also close the dialog, since the dialog is its parent:
请注意,下面的内部对话框是主对话框的子级。这是 v-close-popup
在使用多级窗口时能够关闭两个对话框的唯一方法。否则,如果对话框是同级的(或任何其他类似的情况,其中一个对话框不是另一个对话框的子项),你将必须在对话框上使用 v-model 并自行处理两个对话框的关闭。
¥Notice below that the inner dialog is a child of the main dialog. This is the only way for which v-close-popup
will be able to close both dialogs while using multiple levels. Otherwise, if dialogs are siblings (or any other similar scenario where one dialog is not child of the other), you will have to use v-models on dialogs and handle closing of both dialogs yourself.