js字符串endsWith(), startsWith()方法
数组的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