[Vue基础实战]自定义指令练习
参考代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>自定义指令</title> </head> <body> <div id="app"> <div v-dirzdy="'red'">{{csmsg}}</div> <input v-dirzdy="'red'" type="text"> <input @keyup.delete="cs" type="text"> </div> <script src="../js/vue.js"></script> <script> Vue.directive('dirzdy', { bind(el,binding) { el.style.color=binding.value; }, inserted(el) { el.focus(); } }); const app = new Vue({ el: '#app', data:{ csmsg:"htzd1234" }, methods:{ cs(){ this.csmsg="htzdhhhh"; } } }) </script> </body> </html>