vue.js中關(guān)于點(diǎn)擊事件方法的使用(click)
關(guān)于點(diǎn)擊事件方法的使用(click)
定義vue.js:
<script src="../js/vue.min.js"> </script>
也可以使用網(wǎng)上的:
<script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>
都可以。
定義方法:
let vm=new Vue({
el:"#jincaipinlun",
data:{
message:"",
},
// 點(diǎn)擊頭像查看詳情
methods: {
makereplyName: function(item){
alert(item);
mui.openWindow({
id:13,
url:'myself.html',
extras:{
userName: item
}
});
},
makebeReplyName: function(item){
alert(item);
mui.openWindow({
id:13,
url:'myself.html',
extras:{
userName: item
}
});
} ,
}
});
mui頁(yè)面顯示:
<div data-am-widget="tabs" id="jincaipinlun" class="am-tabs am-tabs-default pet_comment_list_tab am-no-layout">
<div class="am-tabs-bd pet_pl_list" v-for="data in message" style="touch-action: pan-y; user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);">
<div><div class="pet_comment_list_block">
<a >
<div class="pet_comment_list_block_l" v-on:click="makereplyName(data.userName)">
<img v-bind:src=data.img alt="">
</div></a> <div class="pet_comment_list_block_r">
<div class="pet_comment_list_block_r_info">{{data.replyName}}</div>
<div class="pet_comment_list_block_r_text" style="vertical-align: middle;" v-html=data.content>
</div>
<div class="pet_comment_list_block_r_bottom">
<div class="pet_comment_list_bottom_info_l">{{data.time}}</div></div>
</div></div>
<div class="pet_comment_list_block" v-for="item in data.replyBody">
<a >
<div class="pet_comment_list_block_l" v-on:click="makebeReplyName(item.userName)">
<img v-bind:src=item.img alt="">
</div></a> <div class="pet_comment_list_block_r">
<div class="pet_comment_list_block_r_info">{{item.replyName}}</div> <div class="pet_comment_list_block_r_text">
<span>@{{item.beReplyName}}</span><span style="color: rgb(34, 34, 34);" v-html=item.content></span>
</div> <div class="pet_comment_list_block_r_bottom">
<div class="pet_comment_list_bottom_info_l">{{item.time}}</div></div>
</div></div></div>
</div>
</div>
提出重要的方法使用為:
<div class="pet_comment_list_block_l" v-on:click="makereplyName(data.userName)"> <div class="pet_comment_list_block_l" v-on:click="makebeReplyName(item.userName)">
也就是我們提到的:
makereplyName,makebeReplyName方法。
輸出結(jié)果為:


vue點(diǎn)擊click事件解析
vue算是前端技術(shù)比較火的一門(mén)技術(shù)了,所以在日常開(kāi)發(fā)當(dāng)中掌握它還是比較重要的,最近要用vue做一個(gè)移動(dòng)端項(xiàng)目,趁著空閑的時(shí)間來(lái)簡(jiǎn)單的寫(xiě)一下demo:
廢話不多說(shuō),先上代碼:
<!DOCTYPE html>
<html lang="en">
<head>
? ? <meta charset="UTF-8">
? ? <title>Title</title>
? ? <!--<script src="./vue.js"></script>-->
? ? <script src="2.5.20-vue.js"></script>
</head>
<body>
<div id="app">
? ? ?//@click點(diǎn)擊事件getMethod和getMethod()帶不帶小括號(hào)其實(shí)沒(méi)多大的區(qū)別,vue在底層會(huì)把傳過(guò)去的函數(shù)統(tǒng)一解析成為方法,帶小括號(hào)說(shuō)明有相應(yīng)的實(shí)參傳入方法體里面;
? ? <!--<p ? @click="getMethod">aaaa</p>--> ? ? ??
? ? <!--<p ? @click="getMethodFun">aaaa</p>-->
? ? <p ? @click="getMethod()">aaaa</p>
? ? <p ? @click="getMethodFun()">bbbb</p>
</div>
</body>
<script>
? ? var app = new Vue({
? ? ? ? el: '#app',
? ? ? ? data: function () {
? ? ? ? ? ? return {
? ? ? ? ? ? ? ? message: 'father',
? ? ? ? ? ? ? ? show: true
? ? ? ? ? ? };
? ? ? ? },
? ? ? ? methods: {
? ? ? ? ? ? getMethod () { ? ? ?//點(diǎn)擊事件的時(shí)候去尋找相應(yīng)的方法,在底層做轉(zhuǎn)換直接寫(xiě)方法名,大括號(hào)里面寫(xiě)相應(yīng)的業(yè)務(wù)邏輯
? ? ? ? ? ? ? ? console.log('11');
? ? ? ? ? ? },
?//也可以采用匿名函數(shù)的寫(xiě)法定義方法名,然后進(jìn)行調(diào)用這種方法也是可以的,只不過(guò)getMethod ()的寫(xiě)法更加簡(jiǎn)潔,但是在實(shí)際開(kāi)發(fā)當(dāng)中這個(gè)可是不支持的例如 ? aaFunc (){} ? ? ? ? //直接這樣寫(xiě)是會(huì)報(bào)錯(cuò)的,一定要注意;
? ? ? ? ? ? getMethodFun: function () { ??
? ? ? ? ? ? ? ? console.log('22')
? ? ? ? ? ? }
? ? ? ? },
? ? });
</script>
</html>簡(jiǎn)單分析到這里,大家也可以追一下vue的源碼進(jìn)行分析。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
使用vant-uploader上傳照片無(wú)法刪除的解決
這篇文章主要介紹了使用vant-uploader上傳照片無(wú)法刪除的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10
解決router.beforeEach()動(dòng)態(tài)加載路由出現(xiàn)死循環(huán)問(wèn)題
這篇文章主要介紹了解決router.beforeEach()動(dòng)態(tài)加載路由出現(xiàn)死循環(huán)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10
vue中解決chrome瀏覽器自動(dòng)播放音頻和MP3語(yǔ)音打包到線上的實(shí)現(xiàn)方法
這篇文章主要介紹了vue中解決chrome瀏覽器自動(dòng)播放音頻和MP3語(yǔ)音打包到線上的實(shí)現(xiàn)方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10
Vue實(shí)現(xiàn)PC端分辨率自適應(yīng)的示例代碼
本文主要介紹了Vue實(shí)現(xiàn)PC端分辨率自適應(yīng)的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08
vue中filter的應(yīng)用場(chǎng)景詳解
這篇文章主要為大家介紹了vue中filter的應(yīng)用場(chǎng)景,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助2021-11-11
Vue中的ref作用詳解(實(shí)現(xiàn)DOM的聯(lián)動(dòng)操作)
這篇文章主要介紹了Vue中的ref作用詳解(實(shí)現(xiàn)DOM的聯(lián)動(dòng)操作),需要的朋友可以參考下2017-08-08

