janita
V2EX  ›  Vue.js

请教大家一个问题,如下图

  •  
  •   janita · Dec 11, 2016 · 2774 views
    This topic created in 3452 days ago, the information mentioned may be changed or developed.

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>

    <html> <head> <title>指令</title> <script type="text/javascript" src="/plugins/vue/vue.js"></script> </head> <body>
    <input v-wos:zhi.red.border="num">
    <script>
        Vue.directive('wos',{
            bind:function (value) {
                alert(this.el)
                this.el.style.color = '#ff6600';
            },
            update:function (newValue,oldValue) {
                
            },
            unbind:function () {
                
            }
        });
        
        
        new Vue({
            el:"#app",
            data:{
                num:1
            }
        });
    </script>
    
    </body> </html>

    报错:vue:16 Uncaught TypeError: Cannot read property 'style' of undefined,也就是说代码:this.el是undefined,为什么呢? 我这个是直接引入js文件的形式,主要是学习vue的API,有好多的API都没效果,为什么呢?

    kxxoling
        1
    kxxoling  
       Dec 11, 2016
    你没有创建 `#app` 元素啊! https://jsfiddle.net/kxxoling/3Luzu221/
    janita
        2
    janita  
    OP
       Dec 12, 2016 via iPhone
    @kxxoling 哟一会试试
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3680 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 56ms · UTC 10:35 · PVG 18:35 · LAX 03:35 · JFK 06:35
    ♥ Do have faith in what you're doing.