fix(TagsView/index.vue): 修复生产环境获取组件实例的ctx失败的问题

This commit is contained in:
郝先瑞
2022-03-15 12:38:16 +08:00
parent faded7b27c
commit 3d2989b233

View File

@@ -68,6 +68,7 @@ import {
ref,
watch,
onMounted,
ComponentInternalInstance,
} from "vue";
import path from "path-browserify";
@@ -88,7 +89,7 @@ import useStore from "@/store";
const { tagsView, permission } = useStore();
const { ctx } = getCurrentInstance() as any;
const { proxy } = getCurrentInstance() as ComponentInternalInstance; // 获取当前组件实例
const router = useRouter();
const route = useRoute();
@@ -276,8 +277,8 @@ function closeAllTags(view: TagView) {
function openMenu(tag: TagView, e: MouseEvent) {
const menuMinWidth = 105;
const offsetLeft = ctx.$el.getBoundingClientRect().left; // container margin left
const offsetWidth = ctx.$el.offsetWidth; // container width
const offsetLeft = proxy?.$el.getBoundingClientRect().left; // container margin left
const offsetWidth = proxy?.$el.offsetWidth; // container width
const maxLeft = offsetWidth - menuMinWidth; // left boundary
const l = e.clientX - offsetLeft + 15; // 15: margin right