今天发现了另外一种,通过自定义指令,实现获取当前dom:
Vue.directive("run", { inserted (el, binding) { if (typeof binding.value == ‘function‘) binding.value(el); } });
<div name=‘123‘ v-run=‘test‘></div> test(el){ //el就是div }
原文:https://www.cnblogs.com/dells/p/14592294.html