vue 路由的嵌套

vue 路由的嵌套

实现目标:将商品添加的组件add,嵌套在商品列表products中。

1.外层组件 商品列表
const products = {
        template: "#productsTemplate",
        methods: {
            editData: function(val) {
                this.$router.push({
                    name: 'edit',
                    query: val //通过query传值 在切换页面的时候将值传过去
                }, )
            }
        }

    };
2.嵌套组件 商品添加的组件
const add = {
        template: `<div>商品添加form <br>
            <input type="text">
            </div>
        `
    }
3.嵌套的实现

在products的路由规则中,添加children属性,将add组件的路由规则添加在products组件的children属性中。add的地址不能加 /。add路由的路径为 /products/add

const router = new VueRouter({
        routes: [{
            path: '/',
            redirect: '/products' //打开就是用户管理界面
        }, {
            path: '/products',
            component: products,
            name: 'products',
            children: [{
                path: 'add',
                component: add,
                name: 'add',
            }, {
                path: 'edit',
                component: edit,
                name: 'edit',
            }]
        }, ]
    });
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值