为了账号安全,请及时绑定邮箱和手机立即绑定

vue 指令directive如何接受多个参数?

vue 指令directive如何接受多个参数?

慕哥9229398 2019-02-06 11:07:16
假设我有一个只能输入数字的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!"

})


查看完整回答
反对 回复 2019-03-17
?
海绵宝宝撒

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 )
        }
    },
}

这样应该可以。


查看完整回答
反对 回复 2019-03-17
  • 2 回答
  • 0 关注
  • 1527 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信