【问题标题】:Shift box of the checkbox component to the right of label复选框组件的移位框到标签右侧
【发布时间】:2021-08-28 08:01:37
【问题描述】:

我是 vue 新手。我可以问一下吗? 所以,我有复选框组件,我想将此组件的“框”移动到其他组件中标签文本的右侧(例如卡片,默认情况下框在左侧)。但我希望它像一个插槽,有条件的,或者可能使用道具/修饰符(所以我可以选择要求,是左复选框还是右复选框)。可能吗?这是我的代码

卡片组件上的复选框:

<template>
 //component code

    <Checkbox  class="my-checkbox" ref="myCheckbox" v-model="checkedValue" v-if="multiselect"><slot>{{ text }}</slot></Checkbox>
 
 //component code
</template>

复选框模板:

<div class="my-cb">
  <input
    :id="cb"
    v-model="computedValue"
    type="checkbox"
    :disabled="disabled"
    :required="required">
    <label :for="cb">
       <slot />
    </label>
</div>

编辑:感谢 Lais Frigerio,完美解决

【问题讨论】:

  • 您可以使用 flexbox 通过 order 属性更改标签位置

标签: javascript html css vue.js sass


【解决方案1】:

带有弹性框的代码示例:

.flex {
  display: flex;
}

.left label { order: 2; }
.left input { order: 1; }

.right label { order: 1; }
.right input { order: 2; }
<div class="flex left">
  <input type="checkbox" />
  <label>Teste 2</label>
</div>

<div class="flex right">
  <input type="checkbox" />
  <label>Teste 2</label>
</div>

【讨论】:

  • 这个很好用,非常感谢! @Lais Frigerio
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多