zl程序教程

您现在的位置是:首页 >  前端

当前栏目

vue路由传参(学习心得)

Vue路由 传参 学习心得
2023-09-27 14:26:17 时间

如果组件通过query来传递num参数为1,相当与在 url 地址后面拼接参数

<template>  
    <div>  
        <h3>首页</h3>  
        <router-link :to="{ path:'/home/chee', query: { num:  1} }">  
            <button>点击<tton>  
        </router-link>   
        <router-view></router-view>  
    </div>  
</template>  

这是子路由中通过 this.$route.query.num 来显示传递过来的参数URL显示(http://localhost:8080/#/home/chee?num=1)

<template>  
    <h3>农药王者{{ this.$route.query.num }}</h3>  
</template>