janita
V2EX  ›  Vue.js

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

  •  
  •   janita · Dec 11, 2016 · 3115 views
    This topic created in 3625 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
    kxxoling
    Dec 11, 2016
    1
    你没有创建 `#app` 元素啊! https://jsfiddle.net/kxxoling/3Luzu221/
    janita
    janita
    OP
    Dec 12, 2016 via iPhone
    2
    @kxxoling 哟一会试试
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1994 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 10:03 · PVG 18:03 · LAX 02:03 · JFK 05:03
    ♥ Do have faith in what you're doing.