【发布时间】:2021-10-11 19:14:50
【问题描述】:
我有一个带有 3 个可移动面板的侧边栏。我通过使用-translate-x-(amount)(使用TailwindCSS 类)将绑定:class 更改为父<div> 来移动它。当我单击菜单按钮时,我看到 DOM 确实会做出反应并使用正确的 translate-x- 值更改类,但面板不会移动。
链接到沙箱(出于某种原因,它可以在沙箱上运行 - 它也可以在我的 PC 上随机运行,但很少):https://codesandbox.io/s/hopeful-cdn-o38n6?file=/src/App.vue
这是代码:
<template>
<div class="h-screen flex">
<div class="flex container w-40 h-80 bg-black mx-auto my-auto text-black overflow-hidden">
<div class="sidebar container flex transform duration-1000" :class="position">
<div class="sidebar-menu flex-shrink-0 w-40 transform duration-1000 bg-gray-300">
<button @click="currentIndex++">Menu item</button>
</div>
<div class="sidebar-menu flex-shrink-0 w-40 bg-blue-300 transform duration-1000">
<div class="flex flex-col">
<button class="flex justify-start" @click="currentIndex--">
Go back
</button>
<button class="flex justify-start" @click="currentIndex++">
Menu item
</button>
</div>
</div>
<div class="sidebar-menu flex-shrink-0 w-40 transform duration-1000 bg-red-300">
<div class="flex flex-col">
<button class="flex justify-start" @click="currentIndex--">
Go back
</button>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data: () => ({
sidebarWidth: 40,
currentIndex: 0
}),
computed: {
position() {
if (this.currentIndex === 0) {
return 'translate-x-0'
} else {
return `-translate-x-${this.sidebarWidth * this.currentIndex}`}
}
},
}
</script>
【问题讨论】:
标签: vue.js tailwind-css