V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
janita
V2EX  ›  Vue.js

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

  •  
  •   janita · 2016-12-11 13:58:47 +08:00 · 2036 次点击
    这是一个创建于 2717 天前的主题,其中的信息可能已经有所发展或是发生改变。

    <%@ 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  
       2016-12-11 14:24:26 +08:00
    你没有创建 `#app` 元素啊! https://jsfiddle.net/kxxoling/3Luzu221/
    janita
        2
    janita  
    OP
       2016-12-12 07:32:34 +08:00 via iPhone
    @kxxoling 哟一会试试
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5015 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 07:38 · PVG 15:38 · LAX 00:38 · JFK 03:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.