深入理解vue2.0路由如何配置问题
网络编程 2021-07-04 18:32www.168986.cn编程入门
本篇文章主要介绍了vue2.0路由配置问题,长沙网络推广觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随长沙网络推广过来看看吧
这两天学习了Vue.js 感觉路由这个地方知识点挺多的,而且很重要,所以,今天添加一点小笔记。
项目基本手脚架搭建完毕后,建一个router文件夹,里面配置一个index.js文件。
文件内容:
npm install vue-router vue-resource --save-dev(安装 vue 路由模块vue-router和网络请求模块vue-resource)
import Vue from 'vue' import Router from 'vue-router' (----引入路由---注释说明) import About from '@/ponents/about'(--这些需要引入的是ponents文件夹狼蚁网站SEO优化创建的一些模板---相对路径----about代表about.vue模块) import Home from '@/ponents/home' import Brand from '@/ponents/brand' import Company from '@/ponents/pany' import Connect from '@/ponents/connect' import Main from '@/ponents/main' import Join from '@/ponents/join' import News from '@/ponents/news' import Products from '@/ponents/products' import son1 from '@/ponents/son1' import son2 from '@/ponents/son2' import list from '@/ponents/list' import newList from '@/ponents/newList' import culture from '@/ponents/culture' import certification from '@/ponents/certification' import zhuanjia from '@/ponents/zhuanjia' Vue.use(Router) (--使用---) export default new Router({ routes: [ { path: '/main', name: 'main', ponent: Main },-------------------------------- { path: '/', 这里是路由重定向,比如页面加载时候进入首页 redirect: '/main' (比如给路由一个选中后的样式为红色 那么这里就能用到了---.router-link-active{样式}) },--------------------------------- {---------------------这里是配置子路由 path: '/brand', name: 'brand', ponent: Brand, children: [ { path: '/', name: 'newList', ponent: newList }, { path: '/brand/culture', name: 'culture', ponent: culture }, { path: '/brand/certification', name: 'certification', ponent: certification }, { path: '/brand/zhuanjia', name: 'zhuanjia', ponent: zhuanjia } ] }, { path: '/about', name: 'about', ponent: About }, { path: '/pany', name: 'pany', ponent: Company }, { path: '/connect', name: 'connect', ponent: Connect }, { path: '/home', name: 'home', ponent: Home }, { path: '/join', name: 'join', ponent: Join, children: [ { path: '/', name: 'son1', ponent: son1 }, { path: '/join/son2', name: 'son2', ponent: son2 } ] }, { path: '/list', name: 'list', ponent: list }, { path: '/news', name: 'news', ponent: News }, { path: '/products', name: 'products', ponent: Products } ] })
接下来就是在每一个模块文件中加入这样的一句话暴露出去:
<script> export default { name: 'about' ---自定义模块名字 } </script>
在app中我们可以这样写:
<template> <div id="app1" class="pagebox"> <div style="clear:both;"></div> <ul class="index-tap"> <li><router-link to="/main">首页<p></p></router-link></li> <li><router-link to="/about">关于我们<p></p></router-link></li> <li><router-link to="/products">产品专区<p></p></router-link></li> <li><router-link to="/news">新闻资讯<p></p></router-link></li> </ul> <ul class="index-tap"> <li><router-link to="/pany">企业风采<p></p></router-link></li> <li><router-link to="/join">招商加盟<p></p></router-link></li> <li><router-link to="/connect">联系我们<p></p></router-link></li> <li><router-link to="/brand">品牌介绍<p></p></router-link></li> </ul> <div style="clear:both;"></div> <router-view transition transition-mode="out-in"></router-view> <div style="clear:both;"></div> <ul class="index-footer clearx"> <li v-on:click="showph = !showph">电话</li> <li v-on:click="showmap = !showmap">地图</li> <li v-on:click="showd = !showd">分享</li> <!-- JiaThis Button BEGIN --> <transition name="slide-fade"> <div class="jiathis_style_32x32 share" v-show="showd"> <a class="jiathis_button_qzone"></a> <a class="jiathis_button_tsina"></a> <a class="jiathis_button_tqq"></a> <a class="jiathis_button_weixin"></a> <a class="jiathis_button_renren"></a> </div> </transition> <!-- JiaThis Button END --> <transition name="slide-fade"> <div class="share sharephone" v-show="showph"> 18305452462 </div> </transition> <transition name="slide-fade"> <div class="share showmap" v-show="showmap"> <ditu></ditu>---------------------------------自定义模板 </div> </transition> </ul> <div class="fuceng" v-if="showmap"></div> </div> </template> <script> import ditu from '@/ponents/home' export default { name: 'app', data () { return { search: '', showd: false, showph: false, showmap: false } }, mounted () { this.init() }, methods: { Search () { if (this.search !== '') { this.$router.push({ path: '/list', query: { serInfo: this.search } }) } else { alert('请输入搜索内容') } }, init: function () { let url = 'http://v3.jiathis./code/jia.js' let script = document.createElement('script') script.setAttribute('src', url) document.getElementsByTagName('head')[0].appendChild(script) } }, ponents: { ditu } } </script>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程