小码问答,有问必答!

ElementUI中的el-dropdown-item怎么添加click 事件一直报错

Property or method "logout" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.


WEB前端

收藏

1个回答

我要回答

  • author
    牛叔叔 2019-07-28 10:19

    使用官方给的方式,有效。

    <el-dropdown @command="handleCommand">
      <span class="el-dropdown-link">
        下拉菜单<i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="a">黄金糕</el-dropdown-item>
        <el-dropdown-item command="b">狮子头</el-dropdown-item>
        <el-dropdown-item command="c">螺蛳粉</el-dropdown-item>
        <el-dropdown-item command="d" disabled>双皮奶</el-dropdown-item>
        <el-dropdown-item command="e" divided>蚵仔煎</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    
    <style>
      .el-dropdown-link {    
    cursor: pointer;    
    color: #409EFF;
      }  
    .el-icon-arrow-down {    
    font-size: 12px;
      }
    </style>
    
    <script>
      export default {    
          methods: {
            handleCommand(command) {        
            this.$message('click on item ' + command);
            }
          }
      }
    </script>