在elementui中Notification組件添加點擊事件實例
1. 官方文檔

2. 添加點擊事件,傳參
handleClick() {
let telNo = "1111",
message = "22222",
_this = this; //函數(shù)作用域問題
this.$notify({
title: "通知消息",
position: "bottom-right",
dangerouslyUseHTMLString: true,
message: `<p style="cursor: pointer;">號碼:<i>${telNo}</i></p>`,
duration: 0,
type: "warning",
onClick() {
_this.defineCallBack(message); //自定義回調(diào),message為傳的參數(shù)
}
});
},
//點擊事件回調(diào)
defineCallBack(message) {
console.log(message);
},
3. 按一定時間順序彈出消息通知
//按一定時間順序彈出消息通知
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);
}
}
補充知識:vue+elementui怎樣點擊table中的單元格觸發(fā)事件--彈框
elementui中提供了點擊行處理事件
查看位置: elementui的table事件
elementui的table中怎樣點擊某個單元格觸發(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>
點擊單元格彈出框可以使用template-scope方式實現(xiàn)
父組件
<el-table
:data="tableData"
border
style="width: 100%">
<el-table-column
label="編號"
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() {
//從后臺獲取數(shù)據(jù)邏輯 model.CacheModel.get('api/' + this.rowaa + '.json')
//通過this.rowaa就可以獲取傳過來的值
this.formData = 333
}
}
}
</script>
問題解決
可以使用template+slot插值進行管理
點擊找到當(dāng)前行的信息,然后再根據(jù)該信息在子組件中請求數(shù)據(jù)
也試過通過點擊行的事件,判斷在哪一個單元格然后處理事件,這樣也可以,但如果在表格中列存放的內(nèi)容發(fā)生變化又得重新調(diào)整
也試過dialog彈出框直接寫在當(dāng)前單元格的template中,就像官網(wǎng)中例子一樣,但是這樣會在點擊時觸發(fā)多次(次數(shù)與當(dāng)前頁展示的數(shù)量一致)
以上這篇在elementui中Notification組件添加點擊事件實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
說說Vue.js中的functional函數(shù)化組件的使用
這篇文章主要介紹了說說Vue.js中的functional函數(shù)化組件的使用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-02-02
在vue中獲取wangeditor的html和text的操作
這篇文章主要介紹了在vue中獲取wangeditor的html和text的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-10-10
純前端使用Vue3上傳文件到minio文件服務(wù)器(粘貼可直接用)
vue是目前最流行的前端框架,下面這篇文章主要給大家介紹了關(guān)于純前端使用Vue3上傳文件到minio文件服務(wù)器的相關(guān)資料,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2024-04-04
Vue聲明式導(dǎo)航與編程式導(dǎo)航示例分析講解
這篇文章主要介紹了Vue中聲明式導(dǎo)航與編程式導(dǎo)航,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2022-11-11
Antd的Table組件嵌套Table以及選擇框聯(lián)動操作
這篇文章主要介紹了Antd的Table組件嵌套Table以及選擇框聯(lián)動操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-10-10
vue Element左側(cè)無限級菜單實現(xiàn)
這篇文章主要介紹了vue Element左側(cè)無限級菜單實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06

