【问题标题】:Cant handle event in vue.js无法处理 vue.js 中的事件
【发布时间】:2016-06-01 06:35:43
【问题描述】:

我试图在 vue.js 中处理一个事件,但我认为函数 mm 超出了范围。我得到的错误是 [Vue warn]: v-on:mouseover="mm" expects a function value, got undefined 。

这是我的代码

    var menuHover=new Vue({
            e1:'#t',
            data:{
                active:true
            },
            methods: {
                mm: function()
                {
                    alert(1);
                    This.active=!this.active;
                }
            }
        }
    );

这是我的html

        <div id="t" v-on:mouseover="mm">
            <ul v-show="active">
                 <li>Test vue</li>
            </ul>
        </div>

我尝试了几个链接和解决方案,但都没有奏效。

【问题讨论】:

标签: vue.js


【解决方案1】:

试试这个:jsfiddle,我已经运行了这个并且成功了。

   <div id="app" v-on:mouseover="mm">
       {{message}}
        <ul v-show="active">
             <li>Test vue</li>
        </ul>
    </div>

这是js:

 new Vue({
  el: '#app',
   data: {
   active:true,
     message: 'Hello Vue.js!'
   },
    methods: {
            mm: function(){
                alert(1);
                this.active=!this.active;
            }
        }
 })

【讨论】:

  • 括号不是必需的,所以这不是解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-12-31
  • 1970-01-01
  • 2016-02-17
  • 2018-01-03
  • 2017-10-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多