Giter VIP home page Giter VIP logo

Comments (3)

nooooooom avatar nooooooom commented on June 5, 2024

这是因为受控模式导致的,菜单会优先使用 show-menu 这个 props 来控制显示状态。

你将 show-menu 设置为 true 的需求是什么呢,或许我们可以根据需求来探讨更好的使用方式。

from naive-ui.

alan4021 avatar alan4021 commented on June 5, 2024

这是因为受控模式导致的,菜单会优先使用 show-menu 这个 props 来控制显示状态。

你将 show-menu 设置为 true 的需求是什么呢,或许我们可以根据需求来探讨更好的使用方式。

我希望是初始状态为显示让用户知道这个菜单有哪些功能,然后为了为了方便阅读,可以对菜单进行收缩和展开

from naive-ui.

nooooooom avatar nooooooom commented on June 5, 2024

这是因为受控模式导致的,菜单会优先使用 show-menu 这个 props 来控制显示状态。
你将 show-menu 设置为 true 的需求是什么呢,或许我们可以根据需求来探讨更好的使用方式。

我希望是初始状态为显示让用户知道这个菜单有哪些功能,然后为了为了方便阅读,可以对菜单进行收缩和展开

创建一个初始值为 true 变量,假设是 const showMenu = ref(true),然后给组件加上 v-model:show-menu="showMenu" 应该就可以解决了。

有一种特殊情况是,当 menu-trigger 为 'hover' 的时候,鼠标外部移动会使 FloatButton 自动隐藏。如果你希望用户在首次碰到 FloatButton 的之前 FloatButton 不要自动隐藏,你可以自主监听 mousemove 事件,然后调控 showMenu 的受控行为,例如:

const floatButtonRef = ref();

const showMenu = ref(true);
let allowModifyShowMenu = false;

const setShowMenu = (value: boolean) => {
  if (allowModifyShowMenu) {
    showMenu.value = value;
  }
};

const handleMousemove = (e: MouseEvent) => {
  if (floatButtonRef.value?.$el.contains(e.target)) {
    allowModifyShowMenu = true;
    document.removeEventListener("mousemove", handleMousemove);
  }
};

document.addEventListener("mousemove", handleMousemove);

这里是在线用例 https://codesandbox.io/p/sandbox/wonderful-lovelace-vc32yp?file=%2Fsrc%2FDemo.vue%3A41%2C1-59%2C57

from naive-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.