vue.js - Vuetify 抽屉导航拖动以调整大小

标签 vue.js vuejs2 vuetify.js

所以我已经找到了“拖动以调整大小”的位置 - 它只是感觉有点迟钝......有谁知道这可能是为什么,以及如何解决它?

我曾尝试使用 vm.$forceUpdate() 强制刷新,但似乎没有任何效果..

The CodePen can be found here.


编辑: 为这个问题/帖子添加了演示代码工作解决方案。这样,如果 CodePen 出现问题,我们仍然可以使用演示代码。

new Vue({
  el: "#app",
  data: () => {
    return {
      navigation: {
        shown: false,
        width: 200,
        borderSize: 3
      }
    };
  },
  computed: {
    direction() {
      return this.navigation.shown === false ? "Open" : "Closed";
    }
  },
  methods: {
    setBorderWidth() {
      let i = this.$refs.drawer.$el.querySelector(
        ".v-navigation-drawer__border"
      );
      i.style.width = this.navigation.borderSize + "px";
      i.style.cursor = "ew-resize";
      i.style.backgroundColor = "red";
    },
    setEvents() {
      const minSize = this.navigation.borderSize;
      const el = this.$refs.drawer.$el;
      const drawerBorder = el.querySelector(".v-navigation-drawer__border");
      const vm = this;
      const direction = el.classList.contains("v-navigation-drawer--right") ?
        "right" :
        "left";

      function resize(e) {
        document.body.style.cursor = "ew-resize";
        let f =
          direction === "right" ?
          document.body.scrollWidth - e.clientX :
          e.clientX;
        el.style.width = f + "px";
      }

      drawerBorder.addEventListener(
        "mousedown",
        (e) => {
          if (e.offsetX < minSize) {
            el.style.transition = "initial";
            document.addEventListener("mousemove", resize, false);
          }
        },
        false
      );

      document.addEventListener(
        "mouseup",
        () => {
          el.style.transition = "";
          this.navigation.width = el.style.width;
          document.body.style.cursor = "";
          document.removeEventListener("mousemove", resize, false);
        },
        false
      );
    }
  },
  mounted() {
    this.setBorderWidth();
    this.setEvents();
  }
});
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons" rel="stylesheet" />
<link href="https://cdn.jsdelivr.net/npm/vuetify@1.5.6/dist/vuetify.min.css" rel="stylesheet" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@1.5.6/dist/vuetify.min.js"></script>

<div id="app">
  <v-app>
    <v-navigation-drawer ref="drawer" app right hide-overlay :width="navigation.width" v-model="navigation.shown">
      <v-toolbar color="primary">
        <v-toolbar-title class="headline text-uppercase">
          <span>t a</span><span class="font-weight-light"> b s </span>
        </v-toolbar-title>
      </v-toolbar>
      <v-tabs>
        <v-tab v-for="n in 3" :key="n">
          Item {{ n }}
        </v-tab>
        <v-tab-item v-for="n in 3" :key="n">
          <v-card flat>
            <v-card-text>Content for tab {{ n }} would go here</v-card-text>
          </v-card>
        </v-tab-item>
      </v-tabs>
    </v-navigation-drawer>
    <v-container>
      <v-layout justify-center>
        <v-btn @click="navigation.shown = !navigation.shown">Toggle {{ direction }}</v-btn>
      </v-layout>
      <v-layout justify-center>
        <p>Once the navigation drawer is opened, drag it's border to resize (highlited in red)</p>
      </v-layout>
    </v-container>
  </v-app>
</div>

最佳答案

那是因为抽屉导航的过渡效果。在按下鼠标时将过渡设置为初始状态,然后在松开鼠标时将其释放。

在鼠标按下添加

el.style.transition ='initial';

在鼠标上添加

el.style.transition ='';

代码笔:https://codepen.io/dagalti/pen/ywRNYx

关于vue.js - Vuetify 抽屉导航拖动以调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55261712/

相关文章:

vue.js - 我们如何在 NUXTJS 中设置默认路由

javascript - 带有组件标签的 VueJS 路由不起作用

javascript - Vuetify 如何打开和关闭数据表中的对话框

unit-testing - 如何在vue测试用例中传递screen.height和screen.width | Jest 框架

vue.js - Vue 应用程序在通过 npm 的 serve 函数提供服务时工作,但在通过 golang net/http 包提供服务时出现空白页面

vuejs2 - 导入 vue-router 时显示 Vue 未定义错误

javascript - VueJS 动态模型绑定(bind)

javascript - $emit 或 $on 的奇怪行为

javascript - v-img 仅在与常规 img HTML 标记一起使用时出现在 v-for 循环中

css - 组件样式未在生产中应用-Vue