1、首先定義兩個(gè)不同的
.null-input .el-input__inner { background-color: rgba(255, 255, 255, 0.8); color: #525661; font-size: 16px; } .no-null-input .el-input__inner { background-color: rgba(255, 255, 255, 1); color: #524F52; font-size: 16px; }
2、根據(jù):class 控制input的class
:class="{ 'null-input':isNullInput, 'no-null-input':!isNullInput}" @change="changeCss"
3、根據(jù)change方法判斷input的值 然后控制isNullInput的值
changeCss(val) { if (val === "") { this.isNullInput = true; } else { this.isNullInput = false; } console.log(this.isNullInput); }
但是關(guān)于placeholder顏色無法改變
網(wǎng)上的方法試了 沒有效果--網(wǎng)上方法:input::-webkit-input-placeholder
以上這篇vue里input根據(jù)value改變背景色的實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com