神经质女孩 2020-07-21 20:48 采纳率: 0%
浏览 690

【vue项目】for循环中的按钮click点击报错

代码如下:

<template>
  <div class="hello">
      <button @click="msgShow1">我可以</button>

      <p>都是绑定msgShow事件,点击上面的按钮可以,但是点击下面的按钮报错:</p>
      <button v-for="(item,index) in btnsDate" 
      :key="index" 
      @click="item.fun">{{item.name}}</button>
  </div>
</template>

<script>
export default {
  name: 'hello',
  data(){
  return {
    btnsDate:[
      {id:12001,name:"点击按钮1",fun:"msgShow"},
      {id:12002,name:"点击按钮2",fun:"msgShow"},
      {id:12003,name:"点击按钮3",fun:"msgShow"}]
  }
  },
  methods:{  
      msgShow:function(){
        alert("asdasd");
      }
  }
}
</script>

报错1:
[Vue warn]: Error in v-on handler: "TypeError: handler.apply is not a function"

报错2:
TypeError: handler.apply is not a function

请大牛告知原因~

  • 写回答

3条回答 默认 最新

  • 找到Web 2020-07-21 21:55
    关注

    data里面你的item.fun定义的是属性值而不是方法呀,老铁!属性值绑在click事件上不会有效果,而会报错。

    评论

报告相同问题?