使用element-UI的el-dropdown时绑定@click,click事件不触发?

https://img4.mukewang.com/5c909a390001532c08000399.jpg

GCT1015
浏览 7493回答 4
4回答

人到中年有点甜

el-dropdown-item没有自定义click事件, 两个解决办法:使用原生click事件@click.native = "logout"使用菜单项的指令事件<el-dropdown @command="handleCommand"><el-dropdown-item command="logout">退出登录</el-dropdown-item>methods: {&nbsp; &nbsp; handleCommand(command) {&nbsp; &nbsp; &nbsp; &nbsp; if (command === 'logout') {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.logout()&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}

DIEA

不能在item里面直接用@click<el-dropdown-item>&nbsp; &nbsp; <span @click="logout()">退出登录</span></el-dropdown-item>

哆啦的时光机

试试@click.native = "logout()"

阿波罗的战车

<el-dropdown @command="handleCommand"><el-dropdown-item command="logout">退出登录</el-dropdown-item>methods: {&nbsp; &nbsp; handleCommand(command) {&nbsp; &nbsp; &nbsp; &nbsp; this[command]()&nbsp; &nbsp; },&nbsp; &nbsp; logout () {&nbsp; &nbsp; &nbsp; &nbsp; // ...&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript