Vue中router-view無法顯示的解決辦法
如果你存在:
- 代碼沒報(bào)錯,運(yùn)行成功,但是index.js中router掛接的內(nèi)容無法顯示,
- 沒有犯書寫錯誤,routes 和 component 沒有寫錯,
- 在瀏覽器中檢查,App.vue中對應(yīng)的 <router-view>為空
那么建議你接著看,首先,正確的結(jié)果:
//App.vue中
<template>
<div id="app">
//關(guān)鍵是 router-view 能否成功渲染
<router-view></router-view>
<div>
<p>
If Element is successfully added to this project, you'll see an
<code v-text="'<el-button>'"></code>
below
</p>
<el-button>el-button</el-button>
</div>
</div>
</template>
<script>
export default {
name: 'app',
components: {
}
}
</script>//index.js文件
import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/main/HomeView.vue'
import Layout from '../views/LayoutView.vue'
Vue.use(VueRouter)
//1.這里是routes,指定路徑和成員
const routes = [
{
path: '/',
name: 'Layout',
//以下的 component(這是對的) 千萬注意,不要寫成 components(這是錯的)
component: Layout,
children: [
{
path: '',
name: 'Home',
component: HomeView,
meta: {
isLogin: true
}
},
{
path: 'params',
name: 'params',
component: () => import('../views/main/ParamsView.vue'),
meta: {
isLogin: true
}
},
{
path: 'ad',
name: 'ADclassify',
component: () => import('../views/main/ADClassify.vue'),
meta: {
isLogin: true
}
},
{
path: 'product',
name: 'product',
component: () => import('../views/main/ProductView.vue'),
meta: {
isLogin: true
}
}
]
},
{
path: '/login',
name: 'Login',
component: () => import('../views/LoginView.vue'),
meta: {
isLogin: true
}
}
]
//2.這里是router,是一個(gè)VueRouter對象
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
//3.這里是routes,對應(yīng)1中指定的內(nèi)容
})
export default router以上,沒什么問題的話,可以看到

App.vue中對應(yīng)的 <router-view>為是有值的
后來我導(dǎo)入在main.js中了一個(gè)js文件
//main.js
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import './assets/css/common.css'
//導(dǎo)入了這個(gè)文件,之后就看不見 router-view 渲染的內(nèi)容了
// import './router/permission.js'
Vue.config.productionTip = false
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')這里,現(xiàn)在我還是不知道 permission.js 為什么會導(dǎo)致router-view不能渲染
//permission.js
import router from './index'
router.beforeEach((to, from, next) => {
if (to.meta.isLogin) {
const token = false
if (token) {
next()
} else {
next({
name: 'Login'
})
}
} else {
next()
}
})總的來說:Vue中router-view無法顯示可能是導(dǎo)入了什么不合適的文件導(dǎo)致
總結(jié)
到此這篇關(guān)于Vue中router-view無法顯示的解決辦法的文章就介紹到這了,更多相關(guān)Vue router-view無法顯示內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue+Element實(shí)現(xiàn)頁面生成快照截圖
這篇文章主要為大家詳細(xì)介紹了Vue如何結(jié)合Element實(shí)現(xiàn)頁面生成快照截圖功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-03-03
vue-quill-editor插入圖片路徑太長問題解決方法
這篇文章主要介紹了vue-quill-editor插入圖片路徑太長問題解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01

