VueJS选择器占位符在使用v-model且非空时不显示。

huangapple go评论71阅读模式
英文:

VueJS select placeholder does not display with v-model not empty

问题

这是我的代码:

<b-field style="display:inline-block;width:calc(90% / 4);" label="Par Filiale">
    <b-select placeholder="Choix de la filiale" v-model="searchFiliale">
        <option :value="null" disabled>Sélectionner une filiale</option>
        <option :value="''"></option>
        <option
            v-for="filiale in listServicesPartenairesFiliales.filiales"
            :value="filiale.name"
            :key="filiale.id">{{ filiale.name }}
        </option>
    </b-select>
</b-field>

以及数据部分:

data() {
    return {
        searchFiliale: this.$root.getParamUrl('filiale') || '',
    }
},

问题是,b-select的占位符没有显示,因为searchFiliale不为空或null。你是否有一种方法,在保持searchFilialev-model中的同时,正确显示占位符?谢谢!

英文:

here my code :

&lt;b-field style=&quot;display:inline-block;width:calc(90% / 4);&quot; label=&quot;Par Filiale&quot;&gt;
        &lt;b-select placeholder=&quot;Choix de la filiale&quot; v-model=&quot;searchFiliale&quot;&gt;
            &lt;option :value=&quot;null&quot; disabled&gt;S&#233;lectionner une filiale&lt;/option&gt;
            &lt;option :value=&quot;&#39;&#39;&quot;&gt;&lt;/option&gt;
            &lt;option
                v-for=&quot;filiale in listServicesPartenairesFiliales.filiales&quot;
                :value=&quot;filiale.name&quot;
                :key=&quot;filiale.id&quot;&gt;
                {{ filiale.name }}
            &lt;/option&gt;
        &lt;/b-select&gt;
    &lt;/b-field&gt;

And the datas :

data() {
        return {
            searchFiliale: this.$root.getParamUrl(&#39;filiale&#39;) || &#39;&#39;,
        }
    },

The problem is that the placeholder of b-select does not display because searchFiliale is not empty or null.
Do you have an alternative to keep searchFiliale in v-model like here but with the good placeholder ?
Thank you !

答案1

得分: 1

我终于找到了一个临时解决方案:

<option :value="''" disabled selected>Choisir une filiale</option>

这不是一个真正的占位符,但效果是一样的。

如果你有其他解决方案,我很感兴趣。

英文:

I finally found a temporary solution :

&lt;option :value=&quot;&#39;&#39;&quot; disabled selected&gt;Choisir une filiale&lt;/option&gt;

It's not a real placeholder but it's the same effect.

If you have another solution I am interested.

huangapple
  • 本文由 发表于 2020年1月6日 18:17:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/59610279.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定