温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

vue-router中命名路由和命名视图的示例分析

发布时间:2021-07-22 15:55:50 来源:亿速云 阅读:154 作者:小新 栏目:web开发

这篇文章给大家分享的是有关vue-router中命名路由和命名视图的示例分析的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

一、概述

  1. 给路由定义不同的名字,根据名字进行匹配

  2. 给不同的router-view定义名字,router-link通过名字进行对应组件的渲染。

二、代码展示:

目录视图

vue-router中命名路由和命名视图的示例分析

1、命名路由

vue-router中命名路由和命名视图的示例分析 

2、命名视图

index.js

import Vue from 'vue'
import Router from 'vue-router'
import Goodlists from '@/Goodlists/goods'
import Title from '@/Goodlists/title'
import Img from '@/Goodlists/img'
import Cart from '@/Goodlists/cart'
Vue.use(Router)
export default new Router({
 routes: [
 {
 path: '/goods',
 name: 'Goodlists',
 components:{
 default:Goodlists,
 title:Title,
 image:Img,
 } 
 } 
 ]
})

App.vue

<template>
 <div id="app">
 <img src="./assets/logo.png">
 <router-view></router-view>
 <router-view name="title" class="left"></router-view>
 <router-view name="image" class="right"></router-view>
 </div>
</template>

<script>
export default {
 name: 'app'
}
</script>

<style>
#app {
 font-family: 'Avenir', Helvetica, Arial, sans-serif;
 -webkit-font-smoothing: antialiased;
 -moz-osx-font-smoothing: grayscale;
 text-align: center;
 color: #2c3e50;
 margin-top: 60px;
}
.left,.right{
 float: left;
 width:48%;
 text-align: center;
 border:1px solid red
}
</style>

vue-router中命名路由和命名视图的示例分析

感谢各位的阅读!关于“vue-router中命名路由和命名视图的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI