vue中@click如何綁定多個事件
更新時間:2023年11月14日 09:02:51 作者:HaanLen
這篇文章主要介紹了vue中@click如何綁定多個事件問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
vue @click綁定多個事件
<div @click="show();scrollLyric()" class="showImg">
methods: {
show () {
this.$store.commit('show')
},
scrollLyric () {
setTimeout(() => {
let lis = document.querySelectorAll('li')
console.log(lis)
}, 2000)
}vue @click 綁定點擊事件 方法傳遞參數(shù) typescript(通用)
話不多說還是直接上圖 簡單明了

<template>
<div id="header">
<img src="../../assets/logo.jpeg" />
<div v-for="(item,i) in navList" v-bind:key="i" :to="item.path" @click.stop="show(item)">{{item.text}}</div>
<div class="user_msg">
<img src="../../assets/logo.jpeg" />
<span>劉十</span>
</div>
<!-- <span @click="show(shiyan)" >搜索</span> -->
</div>
</template><style lang='less'>
#header {
background: RGBA(54, 55, 66, 1);
color: #fff;
height: 60px;
box-sizing: border-box;
line-height: 60px;
padding: 0px 60px;
display: flex;
align-items: center;
> img {
height: 80%;
}
justify-content: space-between;
.user_msg {
display: flex;
align-items: center;
height: 100%;
> span {
margin-left: 30px;
}
img {
height: 40px;
width: 40px;
border-radius: 20px;
}
}
}
</style><script lang='ts'>
import Vue from "vue";
interface NavItem{
path:String,
text:String,
}
//設置類型
export default Vue.extend({
name: "Nav",
data() {
return {
navList: [
{
path: "/",
text: "首頁"
},
{
path: "/code",
text: "編程"
},
{
path: "/life",
text: "生活"
},
{
path: "/about",
text: "關于"
}
],
shiyan:'898989'
};
},
methods: {
show(e:NavItem) {
console.log(e.path)
}
}
});
</script>總結
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Vue elementUI 自定義表單模板組件功能實現(xiàn)
在項目開發(fā)中,我們會遇到這種需求,在管理后臺添加自定義表單,在指定的頁面使用定義好的表單,這篇文章主要介紹了Vue elementUI 自定義表單模板組件,需要的朋友可以參考下2022-12-12
基于vue監(jiān)聽滾動事件實現(xiàn)錨點鏈接平滑滾動的方法
本篇文章主要介紹了基于vue監(jiān)聽滾動事件實現(xiàn)錨點鏈接平滑滾動的方法,非常具有實用價值,有興趣的可以了解一下2018-01-01

