Vue+ElementUi實現(xiàn)點擊表格鏈接頁面跳轉和路由效果
1、頁面跳轉,先看效果


點擊表格中的asin會跳轉到亞馬遜購物界面
怎么做的呢,直接上代碼
<el-table-column
prop="asin"
label="asin"
width="150"
fixed>
<template slot-scope="scope">
<el-link :href="scope.row.url" rel="external nofollow" type="primary" target="_blank">{{scope.row.asin}}</el-link>
</template>
</el-table-column>asin那一列通過<template>標簽把scope傳進去,scope是包含這一行的信息的,在標簽里面使用<el-link>標簽配合數(shù)據(jù)里面的url實現(xiàn)頁面跳轉,獲取某個屬性可以通過scope.row.屬性名 獲取
2、路由切換加傳參數(shù),先看效果

點擊標題

可以看到路由切換到產品分析了,并且asin數(shù)據(jù)也傳遞過去了
實現(xiàn)直接看代碼(需要注意的是需要傳參的話只能使用name屬性,使用path屬性跳轉是不能傳遞參數(shù)的)
<el-table-column
prop="title"
label="標題"
width="150"
:show-overflow-tooltip="true">
<template slot-scope="scope">
<router-link :to= "{name: 'productsAnalysis',params: {asin: scope.row.asin }}">
<span>
{{scope.row.title}}
</span>
</router-link>
</template>
</el-table-column>可以看到路由切換與頁面跳轉類似,都是通過<template>標簽實現(xiàn)的,區(qū)別就是<router-link>里面直接
{{scope.row.title}}不好使,需要借助<span>標簽實現(xiàn)內容展示路由切換使用路由名字
productsAnalysis,點擊標題時路由器會找到productsAnalysis路由,并且把參數(shù)params傳過去,看一下我的路由怎么實現(xiàn)的吧
{
path: '/console',
component: Layout,
redirect: '/console/productsAnalysis',
name: 'console',
meta: { title: '銷售', icon: 'el-icon-s-help' },
children: [
{
path: 'productsAnalysis',
name: 'productsAnalysis',
component: () => import('@/views/products/productsAnalysis'),
meta: { title: '產品分析', icon: 'table' }
},
{
path: 'productPerspective',
name: 'productPerspective',
component: () => import('@/views/products/productPerspective'),
meta: { title: '產品透視', icon: 'table' }
}
]
},可以看到路由名為productsAnalysis的會跳轉到
@/views/products/productsAnalysis組件

看一下productsAnalysis組件怎么拿到參數(shù)的
<template>
<dev>
<h1>ProductsAnalysis</h1>
<h1>{{asin}}</h1>
</dev>
</template>
<script>
import router from '@/router'
export default {
data(){
return{
asin: null
}
},
created() {
this.asin = this.$route.params.asin
}
}
</script>
<style scoped>
</style>直接
this.$route.params.asin就能拿到路由傳過來的參數(shù)
到此這篇關于Vue+ElementUi實現(xiàn)點擊表格中鏈接進行頁面跳轉和路由的文章就介紹到這了,更多相關Vue ElementUi表格鏈接跳轉內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Vue3中Excel導出的性能優(yōu)化與實戰(zhàn)指南
這篇文章主要為大家詳細介紹了使用Vue3如何實現(xiàn)Excel導出功能并進行優(yōu)化的相關知識,文中的示例代碼講解詳細,感興趣的小伙伴可以了解一下2025-07-07
vue3數(shù)據(jù)監(jiān)聽watch/watchEffect的示例代碼
我們都知道監(jiān)聽器的作用是在每次響應式狀態(tài)發(fā)生變化時觸發(fā),在組合式?API?中,我們可以使用?watch()函數(shù)和watchEffect()函數(shù),下面我們來看下vue3如何進行數(shù)據(jù)監(jiān)聽watch/watchEffect,感興趣的朋友一起看看吧2023-02-02
el-select自定義指令實現(xiàn)觸底加載分頁請求options數(shù)據(jù)(完整代碼和接口可直接用)
某些情況下,下拉框需要做觸底加載,發(fā)請求,獲取option的數(shù)據(jù),下面給大家分享el-select自定義指令實現(xiàn)觸底加載分頁請求options數(shù)據(jù)(附上完整代碼和接口可直接用),感興趣的朋友參考下吧2024-02-02
vite中的glob-import批量導入的實現(xiàn)
本文主要介紹了vite中的glob-import批量導入的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-07-07
vue監(jiān)視器@Watch創(chuàng)建執(zhí)行immediate方式
這篇文章主要介紹了vue監(jiān)視器@Watch創(chuàng)建執(zhí)行immediate方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-08-08
Vue對Element中的el-tag添加@click事件無效的解決
本文主要介紹了Vue對Element中的el-tag添加@click事件無效的解決,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-05-05
利用FetchEventSource在大模型流式輸出的應用方式
這篇文章主要介紹了利用FetchEventSource在大模型流式輸出的應用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-08-08

