首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我正在试用HeadlessUI,Tailwind 2和VueJS v3。为什么在出现开关组件之前,我必须单击HeadlessUI SwitchLabel?

我正在试用HeadlessUI,Tailwind 2和VueJS v3。为什么在出现开关组件之前,我必须单击HeadlessUI SwitchLabel?
EN

Stack Overflow用户
提问于 2021-06-21 17:48:41
回答 1查看 1.2K关注 0票数 0

我正在试用HeadlessUI v1.0、Tailwinv2.2和VueJS v3 (我知道这一点)。但是为什么我必须在开关组件出现之前点击SwitchLabel呢?

一旦开关出现,这两种状态都会出现/正常工作。

我遗漏了什么开关组件吗?

线索:在第一次运行时,我看到(Headless-UI)开关组件(从HTML按钮创建)还没有包含任何类。

从Chrome Dev切换组件(在第一次运行时):

代码语言:javascript
复制
<div class="flex justify-between items-center max-w-sm mx-auto">
    <label id="headlessui-label-1" class="mr-4">Enable notifications</label>
    <button class="" modelvalue="false" id="headlessui-switch-2" role="switch" tabindex="0" type="button" >
        <span class="translate-x-1 inline-block w-4 h-4 transition-transform transform bg-white rounded-full"></span>
    </button>
</div>

App.vue

代码语言:javascript
复制
  <img class="mx-auto" width="100" height="100" alt="Vue logo" src="./assets/logo.png" />

  <HelloWorld msg="HELLO V3 WORLD!" />

  <div class="mt-5 p-5">
    <EnableNotifications />
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import HelloWorld from './components/HelloWorld.vue'
import EnableNotifications from './components/EnableNotifications.vue'

export default defineComponent({
  name: 'App',
  components: {
    HelloWorld,
    EnableNotifications,
  }
})
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

EnableNotifications.vue

代码语言:javascript
复制
<template>
  <SwitchGroup>
    <div class="flex justify-between items-center max-w-sm mx-auto">
      <SwitchLabel class="mr-4">Enable notifications</SwitchLabel>
      <Switch
        v-model="enabled"
        :class='enabled ? "bg-blue-600" : "bg-gray-200"'
        class="relative inline-flex items-center h-6 transition-colors rounded-full w-11 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
      >
        <span
          :class='enabled ? "translate-x-6" : "translate-x-1"'
          class="inline-block w-4 h-4 transition-transform transform bg-white rounded-full"
        />
      </Switch>
    </div>
  </SwitchGroup>
</template>

<script>
  import { ref } from 'vue'
  import { Switch, SwitchGroup, SwitchLabel } from '@headlessui/vue'

  export default {
    components: { Switch, SwitchGroup, SwitchLabel },

    setup() {
      const enabled = ref(false)

      return { enabled }
    },
  }
</script>```
EN

回答 1

Stack Overflow用户

发布于 2021-06-22 02:02:53

刚刚修好了!将HeadlessUI升级到v1.3版本。(我使用的是v1.2)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68072525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档