在选择选项中使用 @click - Vue.js 2 [英] Using @click in select options - Vue.js 2

查看:32
本文介绍了在选择选项中使用 @click - Vue.js 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在选择选项中使用@click.

I'd like to use @click in select options.

到目前为止我有:

<button @click="sortBy('name')">sort by name</button>
<button @click="sortBy('price')">sort by price</button>

它可以工作,但是当我将它插入选项标签时,它停止工作.

and it works, however when I insert it into option tag, it stopped working.

<select name="sortBy" id="sortBy">
  <option value="sort">sort By</option>
  <option @click="sortBy('name')">name</option>
  <option @click="sortBy('price')">price</option>
</select>

我的功能:

sortBy(sortKey) {
    this.items.sort((a, b) =>
    (typeof a[sortKey] === 'string' || typeof b[sortKey] === 'string') ? 
    a[sortKey].localeCompare(b[sortKey]) : a[sortKey] - b[sortKey]);
}

推荐答案

不能绑定事件到,需要使用change

发送“验证码”获取 | 15天全站免登陆