vue 實(shí)現(xiàn)把路由單獨(dú)分離出來
建立一個 router.js 文件
引入
import Vue from 'vue' import VueRouter from 'vue-router' import Home from '../components/home/home.vue'
然后注冊
Vue.use(VueRouter); const router = new VueRouter({ mode : 'history', base: __dirname, routes: [ { path: historyUrl + '/', component: Home, name : '主頁' }, ]}
最后暴露出云
export default router
在main.js 里面直接引入然后就可以用了
import router from './main/router.js' const app = new Vue({ router : router, watch : { '$route' (to,from,next){ //console.log(to) //路由監(jiān)聽 //console.log(from) } }, render : h => h(App) }).$mount('#app');
別的 js 文件如果要調(diào)用 router 方法,直接像 main.js 一樣引入直接用就可以了
補(bǔ)充知識:vue.cli3設(shè)置單獨(dú)路由頁面全屏切換
不是全屏的時候
是全屏的時候
首先思想:獲取當(dāng)前路由頁面的節(jié)點(diǎn),對的節(jié)點(diǎn)操作定位,脫離文檔流,top:0,;left:0;
1.用ref獲取當(dāng)前路由頁面最大的div,也就是template包的第一個div,也可以是其他的
<template> <div ref="index"> //ref標(biāo)識 <Title :refDome='refDome'></Title> </div> </template>
2.如果要把節(jié)點(diǎn)從父組件傳到子組件的話,在data里面定義一個值,然后在mounted賦值,在傳給子組件(如果沒有子組件直接跳過2,直接看3)
父組件
<template> <div ref="index"> <Title :refDome='refDome'></Title> //這里把data的值轉(zhuǎn)給子組件Title </div> </template> <script> import Title from '../components/title' export default { components:{ Title }, data(){ return{ refDome:null } }, mounted(){ this.refDome = this.$refs.index //在這里給data賦值,記得要在mounted賦值 } }
子組件props接收值
<script> export default { props: ['refDome'], } </script>
3.然后在切換全屏的按鈕上綁定@click事件,在點(diǎn)擊當(dāng)時操作節(jié)點(diǎn),在data里面設(shè)置一個screen值為1,為了來回切換
// 點(diǎn)擊切換全屏 handleFullScreen() { if (this.screen % 2 == 0) { this.refDome.style.position = 'static' this.screen++ } else { this.refDome.style.width = '100%' this.refDome.style.height = '100%' this.refDome.style.position = 'absolute' this.refDome.style.top = '0' this.refDome.style.left = '0' this.refDome.style.zIndex = '10' this.refDome.style.background = '#fff' this.screen++ } },
以上這篇vue 實(shí)現(xiàn)把路由單獨(dú)分離出來就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue3?騰訊地圖設(shè)置簽到范圍并獲取經(jīng)緯度的實(shí)現(xiàn)代碼
本文給大家介紹vue3?騰訊地圖設(shè)置簽到范圍并獲取經(jīng)緯度的實(shí)現(xiàn)代碼,本文通過示例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2022-05-05vue鼠標(biāo)懸停事件監(jiān)聽實(shí)現(xiàn)方法
頁面在鼠標(biāo)懸停(不動)n秒之后,頁面進(jìn)行相應(yīng)的事件,下面這篇文章主要給大家介紹了關(guān)于vue鼠標(biāo)懸停事件監(jiān)聽的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09理解Proxy及使用Proxy實(shí)現(xiàn)vue數(shù)據(jù)雙向綁定操作
這篇文章主要介紹了理解Proxy及使用Proxy實(shí)現(xiàn)vue數(shù)據(jù)雙向綁定操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07