Vue和Element UI 路由跳轉

在Vue.js中,使用Vue Router可以方便地實現頁面之間的路由跳轉。Element UI是一個基于Vue 2.0的桌面端組件庫,它本身并不直接提供路由跳轉的功能,但你可以在使用Element UI的Vue項目中結合Vue Router來實現這一功能。

以下是一個基于Vue和Element UI實現路由跳轉的基本步驟:

1.安裝Vue Router

如果你還沒有安裝Vue Router,首先需要安裝它。在你的Vue項目目錄中打開終端或命令提示符,然后運行以下命令:

npm install vue-router  
# 或者  
yarn add vue-router

?

2. 配置Vue Router

在Vue項目中,你需要在src目錄下創建一個router文件夾,并在其中創建一個index.js文件來配置你的路由。以下是一個簡單的示例:

?

// src/router/index.js  import Vue from 'vue'  
import Router from 'vue-router'  
import Home from '@/components/Home'  
import About from '@/components/About'  Vue.use(Router)  export default new Router({  routes: [  {  path: '/',  name: 'Home',  component: Home  },  {  path: '/about',  name: 'About',  component: About  }  ]  
})

?

3. 在Vue實例中使用Vue Router

在你的Vue項目的入口文件(通常是src/main.jssrc/main.ts)中,確保你已經導入了Vue Router,并將其添加到Vue的實例中:

// src/main.js  import Vue from 'vue'  
import App from './App.vue'  
import router from './router'  new Vue({  router,  render: h => h(App),  
}).$mount('#app')

?

4. 使用Element UI組件觸發路由跳轉

現在,你可以在Vue組件中使用Vue Router的編程式導航功能(如this.$router.push)或聲明式導航(<router-link>標簽)來觸發路由跳轉。雖然Element UI本身不直接提供路由跳轉組件,但你可以結合Vue Router的<router-link>標簽或Vue實例的$router.push方法來在Element UI組件中實現路由跳轉。

使用<router-link>

?

<template>  <el-button type="primary" @click="goToAbout">Go to About</el-button>  <!-- 或者使用router-link -->  <router-link to="/about" tag="el-button" type="primary">Go to About</router-link>  
</template>  <script>  
export default {  methods: {  goToAbout() {  this.$router.push('/about');  }  }  
}  
</script>

<template><div><!--搜索框--><div class="top-wrapper"><div class="search el-input el-input--suffix"><inputtype="text"autocomplete="off"placeholder="輸入指標名稱搜索"class="el-input__inner"/></div></div><!--中部--><div class="indicator-wrapper"><!--側邊欄   --><div class="indicator-side"><a:class="{'indicator-category': true,'indicator-category-active': item.checked}"v-for="item in sideList":key="item.id"@click.prevent="categoryClick(item)"href="#!">{{ item.groupName }}</a></div><!--中間選擇器   --><div class="indicator-body"><divclass="indicator-block"v-for="item in sideList":key="item.id":id="item.id"><div class="indicator-group"><span class="indicator-title">{{ item.groupName }} </span></div><div class="el-row"><div class="el-col el-col-8" v-for="el in item.child" :key="el.id"><el-checkbox v-model="el.checked" class="el-checkbox__input el-checkbox"><span class="el-checkbox__label">{{ el.label }}</span></el-checkbox></div></div></div></div><!--拖拽--><div class="flex"><div class="indicator-drag"><div class="indicator-content"><div class="drag-title">已選指標</div><div class="drag-sec">拖動可自定義指標順序</div><div class="indicator-limit_low"><div class="drag-block not-allow mg2">賬號ID</div></div><div class="drag-sepreate">以上指標將橫向固定</div></div><div class="indicator-limit-many" style="max-height: 445px"><sectionv-draggable="[drag,{animation: 150,ghostClass: 'ghost',group: 'people',onUpdate,onAdd,onRemove}]"class="flex flex-col gap-2 p-4 w-300px h-300px m-auto bg-gray-500/5 rounded overflow-auto"><divv-for="item in drag":key="item.id"class="drag-block hover-class all-scroll mg2"@click="dragClick(item)">{{ item.name }}<el-icon@click="removeItem(item.id)"style="float: right;align-items: center;position: relative;top: 8px;"class="mg-icon-close close"><close /></el-icon></div></section><div class="flex justify-between"><preview-list :list="drag" /></div></div></div></div></div></div>
</template><script setup lang="ts">
import { ref } from "vue";
import { vDraggable } from "vue-draggable-plus";
import { Close } from "@element-plus/icons-vue";const sideList = ref([{id: 1,groupName: "基本信息",child: [{prop: "uuid",label: "賬號ID"},{prop: "name",label: "名稱",},{prop: "companyName",label: "公司名稱",},{prop: "allBalance",label: "總余額",}]},{id: 2,groupName: "展現數據",child: [{prop: "updateTime",label: "消耗"},{prop: "summary.spent",label: "曝光量"},{prop: "summary.clickCount",label: "點擊量"},{prop: "summary.downloadCount",label: "下載量"}]},{id: 3,groupName: "轉化數據",child: [{prop: "summary.activateCount",label: "新增激活數"},{prop: "summary.registerCount",label: "游戲注冊量"},{prop: "summary.formsubmitCount",label: "表單提交量"},{prop: "summary.normalActivateCount",label: "普通激活數"},{prop: "summary.backActivateCount",label: "自定義激活數"},{prop: "summary.backRegisterCount",label: "自定義注冊量"},{prop: "summary.addDesktopCount",label: "加桌數"},{prop: "summary.customRetainCount",label: "自定義次留數"},{prop: "summary.gamePayCount",label: "游戲付費數"},{prop: "summary.customPayCount",label: "自定義付費數"},{prop: "summary.reactivation",label: "自定義拉活"},{prop: "summary.webPay",label: "網頁購買"},{prop: "summary.gameAppointment",label: "游戲預約數"},{prop: "summary.buttonClick",label: "按鈕點擊量"},{prop: "summary.fastappPay",label: "快應用付費數"},{prop: "summary.personalizedEvents",label: "個性化事件數"}]},{id: 4,groupName: "轉化數據(計費時間)",child: [{prop: "summary.activateC",label: "新增激活數(按計費時間)"},{prop: "summary.backActivateC",label: "自定義激活數(按計費時間)"},{prop: "summary.backRegisterC",label: "游戲注冊量(按計費時間)"},{prop: "summary.addDesktopC",label: "加桌數(按計費時間)"},{prop: "summary.cDownloadCount",label: "下載數(按計費時間)"},{prop: "summary.customRetainC",label: "自定義次留數(按計費時間)"},{prop: "summary.gamePayC",label: "游戲付費數(按計費時間)"},{prop: "summary.customPayC",label: "自定義付費數(按計費時間)"},{prop: "summary.reactivationC",label: "自定義拉活(按計費時間)"},{prop: "summary.gameAppointmentC",label: "游戲預約數(按計費時間)"},{prop: "summary.firstDayRecoveryAdMonetizationC",label: "首日回收金額-廣告變現(按計費時間)"},{prop: "summary.totalRecoveryAdMonetizationC",label: "累計回收金額-廣告變現(按計費時間)"},{prop: "summary.firstDayRecoveryPaidRechargeC",label: "首日回收金額-充值付費(按計費時間)"},{prop: "summary.totalRecoveryPaidRechargeC",label: "累計回收金額-充值付費(按計費時間)"},{prop: "summary.cFastappPay",label: "快應用付費數(按計費時間)"},{prop: "summary.cPersonalizedEvents",label: "個性化事件數(按計費時間)"},{prop: "summary.cNormalActivateCount",label: "普通激活數(按計費時間)"},{prop: "summary.cCreditCount",label: "自定義授信數(按計費時間)"},{prop: "summary.cInstallDoneCount",label: "安裝完成數(按計費時間)"},{prop: "summary.wechatgameRegisterC",label: "微信小游戲注冊數(按計費時間)"},{prop: "summary.wechatgamePayC",label: "微信小游戲付費數(按計費時間)"},{prop: "summary.cReactivationRetentionCount",label: "拉活自定義次留數(按計費時間)"},{prop: "summary.creditCount",label: "自定義授信數(按轉化時間)"},{prop: "summary.installDoneCount",label: "安裝完成數(按轉化時間)"},{prop: "summary.wechatgameRegisterCount",label: "微信小游戲注冊數(按轉化時間)"},{prop: "summary.wechatgamePayCount",label: "微信小游戲付費數(按轉化時間)"},{prop: "summary.reactivationRetentionCount",label: "拉活自定義次留數(按轉化時間)"},{prop: "summary.reserveCount",label: "日歷預約數(按轉化時間)"},{prop: "summary.taCount",label: "目標用戶量(按轉化時間)"},{prop: "summary.cTaCount",label: "目標用戶量(按計費時間)"},{prop: "summary.payOneTimeCount",label: "應用付費次數(按轉化時間)"},{prop: "summary.cPayOneTimeCount",label: "應用付費次數(按計費時間)"},{prop: "summary.payOneTimeAmount",label: "應用付費金額(按轉化時間)"},{prop: "summary.cPayOneTimeAmount",label: "應用付費金額(按計費時間)"}]},{id: 5,groupName: "互動數據",child: [{prop: "summary.identifyCodeCount",label: "微信-識別二維碼數"},{prop: "summary.addWechatMpaCount",label: "微信-添加微信數"},{prop: "summary.dialogueMpaCount",label: "微信-用戶首次消息數"},{prop: "summary.oneDialogueCount",label: "有效咨詢數"},{prop: "summary.firstDayRecoveryPaidCount",label: "游戲首日首次付費"}]},]);const categoryClick = (item) => {sideList.value.forEach((el) => (el.checked = false));item.checked = !item.checked;const element = document.getElementById( item.id);if (element) {element.scrollIntoView({ behavior: "smooth" });}
};const count = ref(0);const removeItem = (id) => {drag.value = drag.value.filter((item) => item.id != id);
};
// const domeRef = ref<HTMLElement | null>(null);
// const handleClick = (MouseEvent) => {
// 	e.preventDefault();
// };
//拖拽
const drag = ref([{id: 1,name: "賬號ID"},{id: 2,name: "名稱"},{id: 3,name: "賬戶主體"},{id: 4,name: "總余額"}
]);
const dragClick = (item) => {drag.value.forEach((el) => (el.checked = false));item.checked = !item.checked;
};function onUpdate() {console.log("update");
}function onAdd() {console.log("add");
}function onRemove() {console.log("remove");
}
</script><style scoped lang="scss">
::v-deep .el-scrollbar {overflow: hidden;height: 100%;position: static !important;
}::v-deep .el-checkbox__input.is-checked .el-checkbox__inner {background-color: #409eff;//border-color: var(--el-checkbox-checked-input-border-color);
}
//隱藏滾動條
::-webkit-scrollbar-thumb {border-radius: 5px;background-color: rgb(255, 255, 255, 0.2);
}::-webkit-scrollbar {width: 10px;height: 10px;
}
//搜索框
.top-wrapper {display: flex;justify-content: flex-start;margin-bottom: 16px;
}.top-wrapper .search {width: 250px;
}.el-input {position: relative;font-size: 14px;
}.el-input__inner {-webkit-appearance: none;background-color: #fff;background-image: none;border-radius: 4px;border: 1px solid #dcdfe6;box-sizing: border-box;color: #606266;display: inline-block;height: 40px;line-height: 40px;outline: 0;padding: 0 15px;transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);width: 100%;font-size: inherit;-webkit-transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
}
.el-dialog .el-dialog__body .el-input .el-input__inner {padding-left: 8px;color: #333;
}.el-input .el-input__inner {height: 32px;line-height: 32px;border-radius: 2px;
}//側邊欄
.indicator-side .indicator-category {padding-left: 16px;font-size: 14px;line-height: 40px;color: #333;cursor: pointer;display: block;
}.indicator-side .indicator-category-active {color: #197afb;background-color: #d6eaff;
}//中間基本信息
.indicator-block {padding: 16px 0 0 24px;border-bottom: 1px solid #eaebec;
}.indicator-group {display: flex;justify-content: flex-start;
}.indicator-title {margin-bottom: 16px;font-weight: 700;color: #333;
}.el-checkbox__input.is-checked .el-checkbox__label {color: #409eff;
}.el-checkbox__label {color: #333;
}.el-checkbox__label,
.el-radio__label {font-size: 12px;color: #666;
}.el-checkbox__label {display: inline-block;padding-left: 1px;line-height: 19px;font-size: 12px;
}//拖拽
.indicator-drag .indicator-content {padding: 0 16px;
}.indicator-drag .drag-title {font-size: 14px;font-weight: 700;line-height: 100%;color: #333;
}.indicator-drag .drag-sec {margin: 8px 0;font-size: 12px;line-height: 100%;color: #999;
}
.indicator-drag .drag-sepreate {position: relative;margin: 16px 0 0;font-size: 12px;color: #999;text-align: center;
}.indicator-drag .indicator-limit-many {max-height: 445px;padding: 0 16px;margin-top: 16px;overflow-x: hidden;overflow-y: auto;
}.indicator-drag .mg2 {margin-bottom: 2px;
}.indicator-drag .drag-block {position: relative;height: 40px;//width: 134px;padding: 0 30px 0 36px;overflow: hidden;line-height: 40px;text-overflow: ellipsis;white-space: nowrap;background-color: #fff;border-bottom: 1px solid #e8eaec;
}.indicator-drag .drag-block .close {position: absolute;top: 13px;line-height: 100%;color: #cecece;cursor: pointer;
}//滑動條
.infinite-list {width: 160px;height: 300px;padding: 0;margin: 0;list-style: none;
}.infinite-list .infinite-list-item {display: flex;align-items: center;justify-content: center;height: 40px;padding-left: 16px;font-size: 14px;background: #409eff;margin: 10px;color: #409eff;
}.infinite-list .infinite-list-item + .list-item {margin-top: 10px;
}//中部
.indicator-wrapper {display: flex;width: 832px;height: 516px;border: 1px solid #eaebec;border-radius: 4px;
}//側邊欄
.indicator-side {flex-shrink: 0;width: 160px;overflow: auto;border-right: 1px solid #eaebec;
}//選擇器
.indicator-body {width: 672px;overflow: auto;scroll-behavior: smooth;
}//右邊
.indicator-drag {position: absolute;top: 0;right: 0;flex-shrink: 0;width: 216px;//height: 676px;padding: 25px 0;overflow: auto;background-color: #f8f8f9;border-right: 1px solid #eaebec;
}
</style>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/45738.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/45738.shtml
英文地址,請注明出處:http://en.pswp.cn/web/45738.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Proxyman for Mac v5.6.1 抓包調試工具

Mac分享吧 文章目錄 效果一、下載軟件二、功能三、開始安裝1、雙擊運行軟件&#xff0c;將其從左側拖入右側文件夾中&#xff0c;等待安裝完畢2、應用程序顯示軟件圖標&#xff0c;表示安裝成功 四、運行測試1、打開軟件 安裝完成&#xff01;&#xff01;&#xff01; 效果 一…

【華為OD筆試】2024D卷命題規律解讀【分析300+場OD筆試考點總結】

可上 歐弟OJ系統 練習華子OD、大廠真題 綠色聊天軟件戳 od1441了解算法沖刺訓練&#xff08;備注【CSDN】否則不通過&#xff09; 文章目錄 相關推薦閱讀華為OD筆試2024D卷命題規律解讀華為OD算法/大廠面試高頻題算法練習沖刺訓練 相關推薦閱讀 【華為OD筆試】2024D卷機考套題…

C# Opencv實現本地以圖搜圖

地址&#xff1a;馮騰飛/本地以圖搜圖

Java面試八股之Redis哨兵機制

Redis哨兵機制 Redis Sentinel&#xff08;哨兵&#xff09;模式是一種高可用解決方案&#xff0c;用于監控和自動故障轉移Redis主從集群。以下是對哨兵模式詳細過程的描述&#xff1a; 1. 初始化與配置 部署哨兵節點&#xff1a;在不同的服務器上部署一個或多個Redis Sentin…

《算法筆記》總結No.7——二分(多例題詳解版)

一.二分查找 目前有一個有序數列&#xff0c;舉個例子&#xff0c;假設是1~1000&#xff0c;讓我們去查找931這個數字&#xff0c;淺顯且暴力的做法就是直接從頭到尾遍歷一遍&#xff0c;直到找到931為止。當n非常大&#xff0c;比如達到100w時&#xff0c;這是一個非常大的量級…

Linux 線程初步解析

1.線程概念 在一個程序里的一個執行路線就叫做線程&#xff08;thread&#xff09;。更準確的定義是&#xff1a;線程是“一個進程內部的控制序列。在linux中&#xff0c;由于線程和進程都具有id,都需要調度等等相似性&#xff0c;因此都可以用PCB來描述和控制,線程含有PCB&am…

美聯儲降息應該更早?高盛:有充分理由7月降息,而非9月

KlipC報道&#xff1a;高盛首席經濟學家哈祖斯Jan Hatzius表示&#xff0c;美聯儲“有充分理由”在7月會議上降息&#xff0c;而非等到9月。 在最新發布的報告中&#xff0c;他表明通脹已經取得了足夠的進展&#xff0c;回到了美聯儲2%的長期目標附近&#xff0c;這將使美聯儲…

[C++ 入門基礎 - 命名空間]

在C中&#xff0c;命名空間&#xff08;Namespace&#xff09;是一種用來組織代碼并避免命名沖突的機制。命名空間可以包含變量、函數、類等C中的所有實體&#xff0c;使得這些實體的名稱在命名空間內部有效&#xff0c;避免了與其他命名空間或全局作用域中相同名稱的沖突。 文…

實現將Nginx的每個網站配置單獨的訪問日志

一、問題描述 Nginx默認的訪問日志是不會區分哪個網站有哪些日志的,全部糅雜在一起;如果需要哪個網站有哪些訪問日志記錄,還需要將訪問日志下載下來后篩選,比較麻煩;希望將每個網站對應的日志能夠單獨記錄到對應的日志文件里面,方便排查和管理。 # 進入Nginx默認的日志文…

為什么Vim是程序員最喜歡的編輯器之一

簡介 Vim&#xff0c;全稱Vi IMproved&#xff0c;是一種高度可定制、功能強大的文本編輯器。自其誕生以來&#xff0c;它以高效、快速和靈活的特點深受程序員喜愛。無論是處理簡單的文本文件還是復雜的代碼項目&#xff0c;Vim都能提供卓越的編輯體驗。許多資深程序員甚至稱其…

c++ primer plus 第16章string 類和標準模板庫,6.1.5字符串種類

c primer plus 第16章string 類和標準模板庫,6.1.5字符串種類 c primer plus 第16章string 類和標準模板庫,6.1.5字符串種類 文章目錄 c primer plus 第16章string 類和標準模板庫,6.1.5字符串種類6.1.5字符串種類 6.1.5字符串種類 本節將 string 類看作是基于 char 類型的。…

web服務器經過代理后的絕對路徑問題,以及 dirname(__FILE__)和__DIR__

web服務器經過代理后的絕對路徑問題&#xff0c;以及 dirname&#xff08;__FILE__&#xff09;和__DIR__ 問題描述情況解析資源路徑分析訪問過程分析 dirname(\_\_FILE\_\_) 與 \_\_DIR\_\_ 同步發布在個人筆記web服務器經過代理后的絕對路徑問題&#xff0c;以及 dirname(__F…

Nest.js 實戰 (一):使用過濾器優雅地統一處理響應體

前言 在我們實際的業務開發中&#xff0c;我們可以看到后端接口返回格式都有一定的要求&#xff0c;假如我們統一規定接口的統一返回格式為&#xff1a; {data: any; // 業務數據code: number; // 狀態碼msg: string; // 響應信息timestamp: number; // 時間戳 }那么在 Nest.…

【智能算法改進】改進的麻雀搜索算法及其求解旅行商問題

目錄 1.算法原理2.改進點3.結果展示4.參考文獻5.代碼獲取 1.算法原理 【智能算法】麻雀搜索算法&#xff08;SSA&#xff09;原理及實現 2.改進點 改進發現者更新位置 為了使 SSA 算法能夠避開向原點收斂的弊端, 將算法向最優位置跳躍的操作轉換為向最優位置的移動: X i ,…

自己動手寫一個滑動驗證碼組件(后端為Spring Boot項目)

近期參加的項目&#xff0c;主管丟給我一個任務&#xff0c;說要支持滑動驗證碼。我身為50歲的軟件攻城師&#xff0c;當時正背著雙手&#xff0c;好像一個受訓的保安似的&#xff0c;中規中矩地參加每日站會&#xff0c;心想滑動驗證碼在今時今日已經是標配了&#xff0c;司空…

一個篇文章告訴你一個APP前端搭建有多簡單

用uni-app 1.新建uni-app項目 點擊項目 2.創建 最后點擊右下方創建 3.添加tarbar 首先你要創建幾個頁面這里比如說我有兩個頁面的tarbar首頁(home)和我的(userIndex) 在pages目錄下右鍵新建頁面即可

從庫存超賣問題分析鎖和分布式鎖的應用(二)

本文從一個經典的庫存超賣問題分析說明常見鎖的應用&#xff0c;假設庫存資源存儲在Redis里面。 假設我們的減庫存代碼如下&#xff1a; Autowired StringRedisTemplate redisTemplate;public void deduct(){String stock redisTemplate.opsForValue().get("stock"…

JavaSE從零開始到精通

1.前置知識 JVM&#xff1a;java virtrual machine, java虛擬機, 專門用于執行java代碼的一款軟件。JRE&#xff1a;java runtime enviroment, java運行時環境, java官方提供的核心類庫. jre中包含了核心類庫和jvm。JDK: java development kit, java開發工具包, javac.exe, ja…

LVS+Keepalive高可用

1、keepalive 調度器的高可用 vip地址主備之間的切換&#xff0c;主在工作時&#xff0c;vip地址只在主上&#xff0c;vip漂移到備服務器。 在主備的優先級不變的情況下&#xff0c;主恢復工作&#xff0c;vip會飄回到住服務器 1、配優先級 2、配置vip和真實服務器 3、主…

我想做信號通路分析,但我就是不想學編程

“我想做信號通路分析&#xff0c;但我就是不想學編程。” “我又不是生信狗&#xff0c;學代碼會死。” “你們這些做生信的&#xff0c;整天把數據分析搞得神神秘秘&#xff0c;不就是怕被人搶飯碗而已嘛。” “這都沒分析出我想要的結果&#xff0c;不靠譜。” “你們做…