demo.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <div class="pop-over">
  3. <!-- <a @click="toggleOpen" class="pop-button" href="javascript: void(0);">
  4. 123456
  5. </a>
  6. <ul v-clickoutside="close" v-show="open" class="pop-list">
  7. <li>选项1</li>
  8. <li>选项2</li>
  9. <li>选项3</li>
  10. <li>选项4</li>
  11. </ul> -->
  12. <GanChart></GanChart>
  13. <!-- <ProMan></ProMan> -->
  14. </div>
  15. </template>
  16. <script>
  17. import ProMan from "./components/proMan.vue";
  18. import GanChart from "./components/ganChart.vue";
  19. export default {
  20. name: "PopOver",
  21. props: ["buttonText"],
  22. components: {
  23. ProMan,
  24. GanChart,
  25. },
  26. data() {
  27. return {
  28. open: false,
  29. };
  30. },
  31. methods: {
  32. toggleOpen: function () {
  33. this.open = !this.open;
  34. },
  35. close: function (e) {
  36. if (this.$el.contains(e.target)) return;
  37. this.open = false;
  38. },
  39. },
  40. directives: {
  41. clickoutside: {
  42. bind: function (el, binding, vnode) {
  43. const documentHandler = function (e) {
  44. if (!vnode.context || el.contains(e.target)) return;
  45. binding.value(e);
  46. };
  47. setTimeout(() => {
  48. document.addEventListener("click", documentHandler);
  49. }, 0);
  50. },
  51. },
  52. },
  53. };
  54. </script>
  55. <style scoped>
  56. .pop-over {
  57. position: relative;
  58. width: 100%;
  59. height: 100%;
  60. }
  61. .pop-button {
  62. position: relative;
  63. width: 100%;
  64. height: 100%;
  65. text-decoration: none;
  66. color: inherit;
  67. }
  68. .pop-list {
  69. position: absolute;
  70. left: 0;
  71. top: 0;
  72. }
  73. .pop-list li {
  74. width: 100%;
  75. height: 100%;
  76. padding: 8px 3px;
  77. list-style: none;
  78. }
  79. </style>