@mousedown
だけでも良さそうなんですけど、
せっかくなので、タッチデバイスではtouchstart
使用するように、
v-tap
というカスタム・ディレクティブ(グローバル)を作成しました。
※ちなみに、@touchstart
は標準で用意されています。
Vue.directive('tap', {
inserted: function(el, binding) {
const tap = (typeof window.ontouchstart === 'undefined')
? 'mousedown'
: 'touchstart'
let tapFunction = function(event) {
if (binding.value(event, el)) {
el.removeEventListener(tap, tapFunction);
}
};
el.addEventListener(tap, tapFunction);
}
})
See the Pen v-tap directive by pokkur (@pokkur) on CodePen.