在Vue中定义全局指令v-color出错了

在Vue中定义全局指令v-color出错了,错误内容:[Vue warn]: Failed to resolve directive: color
(found in <Anonymous>)
不知道怎么回事?

<!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <title>Title</title> </head> <script src="https://cdn.jsdelivr.net/npm/vue@2.6.6/dist/vue.js"></script> <body> <div id="app">     <h2 v-color>{{msg}}</h2> </div> <script>     var vm=new Vue({         el:"#app",         data:{             msg:'3333ff'         },     })     Vue.directive('color',{         bind:function(el) {             el.style.color='red'         }     }) </script> </body> </html>

v-color出错了,求大神帮忙看看,谢过啦~~


芜湖不芜
浏览 1106回答 2
2回答

慕容3067478

<script>Vue.directive('color',{ &nbsp;&nbsp;&nbsp;&nbsp;bind:function(el)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;el.style.color='red' &nbsp;&nbsp;&nbsp;&nbsp;} })var&nbsp;vm=new&nbsp;Vue({ &nbsp;&nbsp;&nbsp;&nbsp;el:"#app", &nbsp;&nbsp;&nbsp;&nbsp;data:{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg:'3333ff' &nbsp;&nbsp;&nbsp;&nbsp;}, })&nbsp; </script>

哔哔one

你写到new上面去
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript