index.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <div>
  3. <div class="big_box">
  4. <div class="leftBar">
  5. <slot name="leftBar"></slot>
  6. </div>
  7. <div class="dragonet" v-move></div>
  8. <div class="rightBar">
  9. <slot name="rightBar"></slot>
  10. </div>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. name: "SocWebIndex",
  17. data() {
  18. return {
  19. leftWith:0
  20. };
  21. },
  22. directives: {
  23. move(el, bindings, that) {
  24. that = that.context;
  25. el.onmousedown = function (e) {
  26. var init = e.clientX;
  27. var parent = document.querySelector(".leftBar");
  28. // var searchInput = document.querySelector(".input-with-select");
  29. // var parentelement = document.querySelector("#form");
  30. // var formBox = document.querySelector(".formBox");
  31. var initWidth = parent.offsetWidth;
  32. document.onmousemove = function (e) {
  33. var end = e.clientX;
  34. if (end > that.leftWith) {
  35. var newWidth = end - init + initWidth;
  36. parent.style.width = newWidth + "px";
  37. console.log(parent);
  38. } else {
  39. end = that.leftWith + "px";
  40. parent.style.width = that.leftWith + "px";
  41. }
  42. };
  43. document.onmouseup = function () {
  44. document.onmousemove = document.onmouseup = null;
  45. };
  46. };
  47. },
  48. },
  49. mounted() {},
  50. methods: {},
  51. };
  52. </script>
  53. <style lang="scss" scoped>
  54. .big_box {
  55. width: 100%;
  56. display: flex;
  57. .leftBar {
  58. min-width: 200px;
  59. }
  60. .rightBar {
  61. width: 85%;
  62. }
  63. .dragonet {
  64. width: 10px;
  65. min-width: 10px;
  66. cursor: col-resize;
  67. background-color: #fff;
  68. z-index: 5;
  69. }
  70. }
  71. </style>