后台-js代码技巧

本文介绍了JS中的字符串方法endsWith()和startsWith(),以及数组的entries()方法。在Vue方面,讨论了鼠标事件的不同触发,如click.left,click.middle和click.right,以及如何使用@contextmenu.prevent防止默认浏览器行为。此外,还提及了在Vue3中获取元素位置的方法。
摘要由CSDN通过智能技术生成

js字符串endsWith(), startsWith()方法

JS 中实用但是很少人知道的知识:endsWith(), startsWith()_代码搬运媛的博客-CSDN博客

数组的entries()方法

鼠标事件

面试常问的13种Vue修饰符,你都知道吗_那些修饰符有了解过吗面试_W Y L的博客-CSDN博客

1.鼠标的左中右按键触发的事件

<button @click.middle="clickEvent(1)"  @click.left="clickEvent(2)"  @click.right="clickEvent(3)">点我</button>

methods: {
	// 点击中键输出1
	// 点击左键输出2
	// 点击右键输出3
	clickEvent(num) {
		console.log(num)
	}
}

2. vue鼠标右击事件@contextmenu.prevent

需求:阻止浏览器默认事件,添加自定义事件

<div @contextmenu.prevent="rightClick"></div>

vue3 方法返回元素的大小及其相对于视口的位置。

	import {  getCurrentInstance, ComponentInternalInstance } from 'vue'

	const { proxy } = getCurrentInstance() as ComponentInternalInstance

    const offsetLeft = proxy?.$el.getBoundingClientRect().left

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值