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>標簽配合數據里面的url實現(xiàn)頁面跳轉,獲取某個屬性可以通過scope.row.屬性名 獲取
2、路由切換加傳參數,先看效果

點擊標題

可以看到路由切換到產品分析了,并且asin數據也傳遞過去了
實現(xiàn)直接看代碼(需要注意的是需要傳參的話只能使用name屬性,使用path屬性跳轉是不能傳遞參數的)
<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路由,并且把參數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組件怎么拿到參數的
<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就能拿到路由傳過來的參數
到此這篇關于Vue+ElementUi實現(xiàn)點擊表格中鏈接進行頁面跳轉和路由的文章就介紹到這了,更多相關Vue ElementUi表格鏈接跳轉內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Vue-ANTD表單輸入中自定義校驗一些正則表達式規(guī)則介紹
這篇文章主要介紹了Vue-ANTD表單輸入中自定義校驗一些正則表達式規(guī)則介紹,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-01-01
幫助我們高效操作的Virtual?DOM簡單實現(xiàn)
這篇文章主要為大家介紹了幫助我們高效操作Virtual?DOM簡單實現(xiàn)及原理解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-06-06
vue input 輸入校驗字母數字組合且長度小于30的實現(xiàn)代碼
這篇文章主要介紹了vue input 校驗字母數字組合且長度小于30的實現(xiàn)代碼,文章給大家補充介紹了在Vue.Js下使用el-input框只能輸入數字并限制位數并且限制中文輸入以及粘貼功能,感興趣的朋友跟隨腳本之家小編一起看看吧2018-05-05

