我想將computed
樣式應用於輸入表單。 documentation解釋瞭如何做到這一點,但只適用於簡單的樣式。如何在vue.js中使用屬性選擇器?
我需要申請的
input[type="text"], textarea {
background-color : red;
}
但相當於目前尚不清楚對我如何傳達[type="text"]
位。
使用它逐字不起作用:
var vm = new Vue({
el: "#root",
data: {
password: '',
},
computed: {
passwordStyle: function() {
var style = {}
style['input[type="text"]'] = 'red';
style['textarea'] = 'blue';
return style;
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.10/vue.min.js"></script>
<div id="root>">
<input type="text" name="password" autofocus="true" v-bind:style='passwordStyle'>
</div>
謝謝。我很專注於我的代碼,我沒有意識到,在這個例子中,我忘了通過'background-color' ...... – WoJ