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

假设我有一个只能输入数字的input,并且长度和小数点后位数有限制,那么我就需要两个参数了,我该如何传递和指令里面获取呢?

下面是我传递一个参数或获取的代码,如下:

<input type="text" v-spec-input='8'>

directives: {    spec_input: {
        bind: function (el, binding) {
            //获取
            console.log(binding.value)
        }
    },
}


慕哥9229398
浏览 1530回答 2
2回答

MYYA

<div v-demo="{ color: 'white', text: 'hello!' }"></div>Vue.directive('demo', function (el, binding) {&nbsp; console.log(binding.value.color) // => "white"&nbsp; console.log(binding.value.text)&nbsp; // => "hello!"})

海绵宝宝撒

<input&nbsp;type="text"&nbsp;numberLength='8'&nbsp;pointLength='3'>directives:&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;spec_input:&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bind:&nbsp;function&nbsp;(el,&nbsp;binding)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//获取 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(el.attributes.numberLength.value,el.attributes.pointLength.value&nbsp;) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;}, }这样应该可以。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

AngularJS