Subscribe on changes!

el.attributes.length is wrong in directive.(自定义指令中,el.attributes.length 与实际不符,el.attributes.length 总为0)

avatar
Sep 18th 2021

Version

3.2.12

Reproduction link

codepen.io

Steps to reproduce

// v-directive app.directive('test', { created(el, binding) { console.log('attributes.length:', el.attributes.length) // 0 } }) // test.vue

something

What is expected?

console.log(el.attributes.length) // 2

What is actually happening?

console.log(el.attributes.length) // 0

avatar
Sep 18th 2021

You need the mounted hook for that

avatar
Sep 18th 2021

Directive created hook is invoked before prop is patched on el, try other hooks instead.