假設我有一個只能輸入數字的input,并且長度和小數點后位數有限制,那么我就需要兩個參數了,我該如何傳遞和指令里面獲取呢?下面是我傳遞一個參數或獲取的代碼,如下:<input type="text" v-spec-input='8'>directives: { spec_input: {
bind: function (el, binding) {
//獲取
console.log(binding.value)
}
},
}
2 回答

MYYA
TA貢獻1868條經驗 獲得超4個贊
<div v-demo="{ color: 'white', text: 'hello!' }"></div>
Vue.directive('demo', function (el, binding) {
console.log(binding.value.color) // => "white"
console.log(binding.value.text) // => "hello!"
})

海綿寶寶撒
TA貢獻1809條經驗 獲得超8個贊
<input type="text" numberLength='8' pointLength='3'>
directives: { spec_input: { bind: function (el, binding) { //獲取 console.log(el.attributes.numberLength.value,el.attributes.pointLength.value ) } }, }
這樣應該可以。
- 2 回答
- 0 關注
- 1584 瀏覽
添加回答
舉報
0/150
提交
取消