在elementui中Notification組件添加點(diǎn)擊事件實(shí)例
1. 官方文檔
2. 添加點(diǎn)擊事件,傳參
handleClick() { let telNo = "1111", message = "22222", _this = this; //函數(shù)作用域問(wèn)題 this.$notify({ title: "通知消息", position: "bottom-right", dangerouslyUseHTMLString: true, message: `<p style="cursor: pointer;">號(hào)碼:<i>${telNo}</i></p>`, duration: 0, type: "warning", onClick() { _this.defineCallBack(message); //自定義回調(diào),message為傳的參數(shù) } }); }, //點(diǎn)擊事件回調(diào) defineCallBack(message) { console.log(message); },
3. 按一定時(shí)間順序彈出消息通知
//按一定時(shí)間順序彈出消息通知 notifyByOrder() { let data = ["aaaa", "bbbbb", "ccccc"]; for (let i = 0; i < data.length; i++) { let item = data[i]; setTimeout(() => { this.$notify({ title: `通知${i + 1}`, position: "bottom-right", message: `通知內(nèi)容${item}`, duration: 0, type: "warning" }); }, i * 5000); } }
補(bǔ)充知識(shí):vue+elementui怎樣點(diǎn)擊table中的單元格觸發(fā)事件--彈框
elementui中提供了點(diǎn)擊行處理事件
查看位置: elementui的table事件
elementui的table中怎樣點(diǎn)擊某個(gè)單元格觸發(fā)事件?
可以先看一下官網(wǎng)中table的自定義列模板代碼
<template> <el-table :data="tableData" border style="width: 100%"> <el-table-column label="日期" width="180"> <template scope="scope"> <el-icon name="time"></el-icon> <span style="margin-left: 10px">{{ scope.row.date }}</span> </template> </el-table-column> <el-table-column label="姓名" width="180"> <template scope="scope"> <el-popover trigger="hover" placement="top"> <p>姓名: {{ scope.row.name }}</p> <p>住址: {{ scope.row.address }}</p> <div slot="reference" class="name-wrapper"> <el-tag>{{ scope.row.name }}</el-tag> </div> </el-popover> </template> </el-table-column> <el-table-column label="操作"> <template scope="scope"> <el-button size="small" @click="handleEdit(scope.$index, scope.row)">編輯</el-button> <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">刪除</el-button> </template> </el-table-column> </el-table> </template>
<script> export default { data() { return { tableData: [{ date: '2016-05-02', name: '王小虎', address: '上海市普陀區(qū)金沙江路 1518 弄' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀區(qū)金沙江路 1517 弄' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀區(qū)金沙江路 1519 弄' }, { date: '2016-05-03', name: '王小虎', address: '上海市普陀區(qū)金沙江路 1516 弄' }] } }, methods: { handleEdit(index, row) { console.log(index, row); }, handleDelete(index, row) { console.log(index, row); } } } </script>
點(diǎn)擊單元格彈出框可以使用template-scope方式實(shí)現(xiàn)
父組件
<el-table :data="tableData" border style="width: 100%"> <el-table-column label="編號(hào)" prop = "number" width="180"> <template scope="scope"> <div style="color:red;text-decoration:underline;cursor:pointer;" @click="getMore(scope.row)">{{ scope.row.date }}</div> </template> </el-table-column> <el-table-column label="名稱" prop = "name" width="180"> <template scope="scope"> <div style="color:red;text-decoration:underline;cursor:pointer;" @click="getMore2(scope.row)">{{ scope.row.date }}</div> </template> </el-table-column> </el-table> <el-dialog :visible-sync="getA"> <my-component :rowaa=row></my-component> </el-dialog> <el-dialog :visible-sync="getB"> <my-component2 :rowaa=row></my-component2> </el-dialog>
<script> import myComponent from './mycomponent' import myComponent2 form './mycomponent2' export default { data() { return { tableData : [ {"number" : 1,"name":"y"}, {"number" : 2,"name":"x"}, ], getA : false, getB : false, row : '' } }, components: { 'my-component' : myComponent, 'my-component2' : myComponent2 }, methods : { getMore(row) { this.getA = true this.row = row }, getMore2(row) { this.getB = true this.row = row } } } </script>
子組件 mycomponent
<div>{{formData}}</div> <script> export default { props: ['rowaa'], data() { return { formData:'' } }, created() { this.getData() }, watch : { 'rowaa' : 'getData' }, methods: { getData() { //從后臺(tái)獲取數(shù)據(jù)邏輯 model.CacheModel.get('api/' + this.rowaa + '.json') //通過(guò)this.rowaa就可以獲取傳過(guò)來(lái)的值 this.formData = 333 } } } </script>
問(wèn)題解決
可以使用template+slot插值進(jìn)行管理
點(diǎn)擊找到當(dāng)前行的信息,然后再根據(jù)該信息在子組件中請(qǐng)求數(shù)據(jù)
也試過(guò)通過(guò)點(diǎn)擊行的事件,判斷在哪一個(gè)單元格然后處理事件,這樣也可以,但如果在表格中列存放的內(nèi)容發(fā)生變化又得重新調(diào)整
也試過(guò)dialog彈出框直接寫(xiě)在當(dāng)前單元格的template中,就像官網(wǎng)中例子一樣,但是這樣會(huì)在點(diǎn)擊時(shí)觸發(fā)多次(次數(shù)與當(dāng)前頁(yè)展示的數(shù)量一致)
以上這篇在elementui中Notification組件添加點(diǎn)擊事件實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
說(shuō)說(shuō)Vue.js中的functional函數(shù)化組件的使用
這篇文章主要介紹了說(shuō)說(shuō)Vue.js中的functional函數(shù)化組件的使用,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-02-02在vue中獲取wangeditor的html和text的操作
這篇文章主要介紹了在vue中獲取wangeditor的html和text的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10純前端使用Vue3上傳文件到minio文件服務(wù)器(粘貼可直接用)
vue是目前最流行的前端框架,下面這篇文章主要給大家介紹了關(guān)于純前端使用Vue3上傳文件到minio文件服務(wù)器的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-04-04Vue聲明式導(dǎo)航與編程式導(dǎo)航示例分析講解
這篇文章主要介紹了Vue中聲明式導(dǎo)航與編程式導(dǎo)航,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2022-11-11Antd的Table組件嵌套Table以及選擇框聯(lián)動(dòng)操作
這篇文章主要介紹了Antd的Table組件嵌套Table以及選擇框聯(lián)動(dòng)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10解決vant-UI庫(kù)修改樣式無(wú)效的問(wèn)題
這篇文章主要介紹了解決vant-UI庫(kù)修改樣式無(wú)效的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11vue Element左側(cè)無(wú)限級(jí)菜單實(shí)現(xiàn)
這篇文章主要介紹了vue Element左側(cè)無(wú)限級(jí)菜單實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06vue頁(yè)面加載時(shí)的進(jìn)度條功能(實(shí)例代碼)
這篇文章主要介紹了vue頁(yè)面加載時(shí)的進(jìn)度條功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-01-01