<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <script src="vue.js"></script> <title id="title">{{title}}</title> </head> <body> <div id="ask"><!--vue不能控制body和html的標簽--> <!--鼠標左鍵--> <div :style="left_style" @click.left="mouseclick('左')"></div> <!--鼠標中鍵--> <div :style="middle_style" @click.middle="mouseclick('中')"></div> <!--鼠標右鍵--> <!--加prevent為了屏蔽瀏覽器自帶右鍵--> <div :style="right_style" @contextmenu.prevent="mouseclick('右')"></div> </div> <script> var vue = function (options){new Vue(options)}; vue({ el:'#title', data:{ title:'Vue 監聽鼠標左鍵 鼠標右鍵以及鼠標中鍵修飾符click.left&contextmenu&click.middle' } }); var app = vue({ el:'#ask', data:{ left_style:{border:'solid 2px red',height:'200px'}, right_style:{border:'solid 2px blue',height:'200px'}, middle_style:{border:'solid 2px yellow',height:'200px'}, }, methods:{ mouseclick(where){ alert('點擊鼠標'+where+'鍵觸發'); }, } }); </script> </body> </html>