<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <script src="https://unpkg.com/vue/dist/vue.js"></script> </head> <body> <div v-demo-directive="{ color: 'white', text: 'hello!' }"></div> <script> Vue.directive('demoDirective', function(el, binding, vnode){ console.log(binding.value.color); console.log(binding.value.text); }); var demo = new Vue({ el: '#hook-arguments-example' }) </script> </body> </html>
运行截图:
字面指令
若在创建自定义指令时,设置isLiterral: true,则特性值被视作字符串,并赋给该指令的expression,字面指令不会建立数据监视。
参考链接