当前位置: 代码迷 >> 综合 >> 06nodejs 第9天 VUE 第3天 自定义指令
  详细解决方案

06nodejs 第9天 VUE 第3天 自定义指令

热度:48   发布时间:2023-10-10 23:43:12.0

 全局作用

Vue.directive('haha',{inserted:function(elment){elment.style.color = 'red';}});

局部作用

directives:{haha:{inserted: function (elment) {elment.style.color = 'red';}}}

HTML 

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><script src="./vue.js"></script>
</head><body><div id="app"><p v-bind:class="msg"></p><p v-haha>123hahaha</p></div>
</body>
<script>// 定义一个全局指令/* Vue.directive('haha',{inserted:function(elment){elment.style.color = 'red';}}); */var app = new Vue({el: '#app',data: {msg:'hello'},methods: {},// 局部自定义指令directives:{haha:{inserted: function (elment) {elment.style.color = 'red';}}}});
</script></html>