您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關vue如何新建項目并配置標準路由的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
配置路由所有用到的地方總共四步或者說四處
1.index.js(src--router--index.js)
import Vue from 'vue' import Router from 'vue-router' // import HelloWorld from '@/components/HelloWorld' import Home from '@/components/layout/Home' import showuser from '@/components/t_dom_owner_user/showuser' import addusersfromother from '@/components/t_dom_owner_user/addusersfromother' import showresT from '@/components/t_dom_owner_resT/showresT' Vue.use(Router) export default new Router({ // routes: [ // { // path: '/', // name: 'Login', // component: Login // } // ] routes: [ { path: '/', name: 'Home', component: Home , children: [ { path: '/showuser', name: 'showuser', component: showuser, }, { path: '/showresT', name: 'showresT', component: showresT }] }, { path: '/addusersfromother', name: 'addusersfromother', component: addusersfromother }, ] })
2.main.js(src根目錄下)
import Vue from 'vue' import App from './App.vue' import ElementUI from 'element-ui'; import router from './router' import 'element-ui/lib/theme-chalk/index.css'; import '../public/css/main.css' import store from '../store' Vue.config.productionTip = false; Vue.use(ElementUI); new Vue({ router, render: h => h(App), store, }).$mount('#app')
3.App.vue
<template> <div id="app"> <!--<img alt="Vue logo" src="./assets/logo.png">--> <!--<HelloWorld msg="Welcome to Your Vue.js App"/>--> <!--<home></home>--> <router-view></router-view> </div> </template> <script> // import HelloWorld from './components/HelloWorld.vue' //import Home from "./components/layout/Home"; export default { name: "app", components: { // HelloWorld //Home }, }; </script> <style> #app { width: 100%; height: 100%; } </style>
注意App.vue里的<router-view></router-view>必須配置,這意味著項目運行起始的路由界面,
即對應index.js里配置的根路徑http://localhost:8080/#,作為app.vue的入口頁面
path: '/', name: 'Home', component: Home ,
4.其它應用路由的界面
比如showowner.vue
<template> <div> <!-- <el-tree :data="data" @node-click="handleNodeClick"></el-tree> --> <el-container> <el-aside width="200px"> <el-tree :data="data" node-key="id" :props="defaultProps" :expand-on-click-node="false" :highlight-current="true" @node-click="handleNodeClick" > <span class="custom-tree-node" slot-scope="{ node, data }"> <span>{{ data.data.ownerName}}</span> <span> <el-button type="text" size="mini"> <i class="el-icon-edit"></i> </el-button> <el-button type="text" size="mini"> <i class="el-icon-plus"></i> </el-button> <el-button type="text" size="mini"> <i class="el-icon-delete"></i> </el-button> </span> </span> </el-tree> </el-aside> <el-main> <el-col :span="24" class="content-wrapper"> <transition name="fade" mode="out-in"> <router-view></router-view> </transition> </el-col> </el-main> </el-container> </div> </template>
其中的嵌入式布局el-main里配置<router-view></router-view>,意味著在本界面showowner.vue觸發路由將要跳轉的位置,即要跳轉到el-main處
<el-main> <el-col :span="24" class="content-wrapper"> <transition name="fade" mode="out-in"> <router-view></router-view> </transition> </el-col> </el-main>
然后是跳轉路由寫法,跳轉到的界面是pathVariable,界面pathVariable就會顯示在上面配置的el-main處
handleNodeClick(data) { console.log(data); //每次點擊結點都要初始化ownerId this.domId = data.data.domId; this.ownerId = data.data.ownerId; this.varify(); this.$router.push({ path: this.pathVariable, query: { domId: this.domId, ownerId: this.ownerId } }); }
感謝各位的閱讀!關于“vue如何新建項目并配置標準路由”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。