我是web開(kāi)發(fā)的新手,我在處理vue時(shí)遇到了問(wèn)題。從教程中我學(xué)到,當(dāng)按鈕被按下時(shí)可以使用@click。它運(yùn)行得很好。
現(xiàn)在我想做一個(gè)簡(jiǎn)單的測(cè)量,檢測(cè)鼠標(biāo)的按下和抬起,以便進(jìn)一步開(kāi)發(fā)雙擊和長(zhǎng)按檢測(cè)器(我也發(fā)現(xiàn)可以使用@double-click,但由于未知原因它也不起作用)。你能解釋一下我做錯(cuò)了什么嗎?
注意:我知道有很多處理這個(gè)問(wèn)題的包,但如果可能的話(huà),我想保持簡(jiǎn)單。
<script> export default { data() { return { counter: 0, } }, methods: { greet(event) { this.counter = 2 } } } </script> <template> <button @mouse-down="greet">問(wèn)候 {{ counter }}</button> </template>
事件名稱(chēng)是"@mousedown"而不是"@mouse-down"
<button @mousedown="greet">問(wèn)候 {{ counter }}</button>
但是要小心處理這個(gè)事件。它處理所有的鼠標(biāo)按鈕(左鍵、中鍵、右鍵),并且在按下任何一個(gè)按鈕時(shí)調(diào)用。
要處理只有一個(gè)按鈕按下的事件,你應(yīng)該使用".left"或".right"修飾符。
例如:
<button @mousedown.left="greet">問(wèn)候 {{ counter }}</button>
它只會(huì)在左鍵按下時(shí)處理。