2019-12-14 02:05:31 +08:00
|
|
|
# 手动定位
|
|
|
|
在特殊情况下,你可能想手动定位下拉菜单。比如在一块区域右击以弹出下拉菜单。
|
|
|
|
```html
|
|
|
|
<div style="width: 200px; height: 200px; background-color: rgba(0, 128, 0, .5);" @contextmenu="handleContextMenu">
|
|
|
|
右击
|
|
|
|
</div>
|
|
|
|
<n-dropdown
|
|
|
|
placement="bottom-start"
|
|
|
|
trigger="manual"
|
|
|
|
manually-positioned
|
|
|
|
@select="handleSelect"
|
|
|
|
@blur="handleBlur"
|
|
|
|
:x="x"
|
|
|
|
:y="y"
|
2020-02-04 22:07:55 +08:00
|
|
|
:options="options"
|
|
|
|
:show="showDropdown"
|
|
|
|
/>
|
2019-12-14 02:05:31 +08:00
|
|
|
```
|
|
|
|
```js
|
2020-02-04 22:07:55 +08:00
|
|
|
const options = [
|
|
|
|
{
|
|
|
|
label: '杰·盖茨比',
|
2020-03-08 19:24:07 +08:00
|
|
|
value: 'jay gatsby'
|
2020-02-04 22:07:55 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '黛西·布坎南',
|
2020-03-08 19:24:07 +08:00
|
|
|
value: 'daisy buchanan'
|
2020-02-04 22:07:55 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'divider'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '尼克·卡拉威',
|
2020-03-08 19:24:07 +08:00
|
|
|
value: 'nick carraway'
|
2020-02-04 22:07:55 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '其他',
|
2020-03-08 19:24:07 +08:00
|
|
|
value: 'others',
|
2020-02-04 22:07:55 +08:00
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: '乔丹·贝克',
|
2020-03-08 19:24:07 +08:00
|
|
|
value: 'jordan baker'
|
2020-02-04 22:07:55 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '汤姆·布坎南',
|
2020-03-08 19:24:07 +08:00
|
|
|
value: 'tom buchanan'
|
2020-02-04 22:07:55 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '其他',
|
2020-03-08 19:24:07 +08:00
|
|
|
value: 'others',
|
2020-02-04 22:07:55 +08:00
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: '鸡肉',
|
2020-03-08 19:24:07 +08:00
|
|
|
value: 'chicken'
|
2020-02-04 22:07:55 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '牛肉',
|
2020-03-08 19:24:07 +08:00
|
|
|
value: 'beef'
|
2020-02-04 22:07:55 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2019-12-14 02:05:31 +08:00
|
|
|
export default {
|
|
|
|
methods: {
|
|
|
|
handleSelect (name) {
|
|
|
|
this.showDropdown = false
|
|
|
|
this.$NMessage.info(name)
|
|
|
|
},
|
|
|
|
handleBlur () {
|
|
|
|
this.showDropdown = false
|
|
|
|
},
|
|
|
|
handleContextMenu (e) {
|
|
|
|
e.preventDefault()
|
|
|
|
this.showDropdown = false
|
|
|
|
this.$nextTick().then(() => {
|
|
|
|
this.showDropdown = true
|
|
|
|
this.x = e.clientX
|
|
|
|
this.y = e.clientY
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
2020-02-04 22:07:55 +08:00
|
|
|
options,
|
2019-12-14 02:05:31 +08:00
|
|
|
showDropdown: false,
|
|
|
|
x: 0,
|
|
|
|
y: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-04 22:07:55 +08:00
|
|
|
```
|