更改 Buefy 库 (Vue.js) 的 TagInput 元素中的默认行为?

Change default behavior in TagInput element of Buefy library (Vue.js)?

在我的 Vue.js (version 2.5.22) 应用程序中,我使用 Buefy 库中的 UI 组件。我使用 taginput 元素。如果我有 5 个标签的限制,如下例所示,当输入有 5 个标签时,边框会消失。

问题:是否可以更改此行为?无论如何我都想显示边框。

<b-field label="Limited to 10 characters and 5 tags">
    <b-taginput maxtags="5":value="['Red', 'Green', 'Blue', 'White']">
    </b-taginput>
</b-field>

没有这个道具。您可以将 class 属性添加到 b 字段组件标签:

<b-field class="always-show" label="Limited to 10 characters and 5 tags">
    <b-taginput maxtags="5" :value="['Red', 'Green', 'Blue', 'White']">
    </b-taginput>
</b-field>

然后为新的添加样式 class:

.always-show .taginput-container{
  box-shadow: inset 0 1px 2px hsla(0,0%,4%,.1);
  border: 1px solid #b5b5b5;
  border-radius: 4px;
  padding: calc(.375em - 1px) calc(.625em - 1px);
}

我有一个建议,也许是不同的方式,你不需要修改默认的限制行为: 1.不限制输入的标签数量。 2.添加时判断,如果超过5个,则删除第一个

  • 模板
<b-field label="Limited to 10 characters and 5 tags">
    <b-taginput @add="onAdd" :value="tags">
    </b-taginput>
</b-field>
  • js
data() {
  return {
    tags: []
  }
}
onAdd(){
  if (this.tags.length > 5) {
    this.tags.shift();
  }
}

嗯,在我的例子中,我使用这样的风格:

<b-field class="always-show" label="Limited to 10 characters and 5 tags">
    <b-taginput maxtags="5" :value="['Red', 'Green', 'Blue', 'White']">
    </b-taginput>
</b-field>

CSS:

.always-show .taginput-container {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    height: auto;
    cursor: text;
    border-color: #dbdbdb;
    color: #363636;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
    clear: both;
    font-size: 1rem;
    position: relative;
    text-align: left;
    border-radius: 4px;
    -webkit-box-shadow: inset 0 1px 2px rgba(10, 10, 10, 0.1);
    background-color: #fff;
    box-shadow: inset 0 1px 2px hsla(0,0%,4%,.1);
    padding: calc(.375em - 1px) calc(.625em - 1px);
    line-height: 1.5;
  }