axios中url参数变量配置

首先在route的配置文件中配置

变量前加:,这样就能传参给相应组件了

{
            path:'/user/:name',
            name:'user_info',
            component:UserInfo
        },

在相应组件中,写axios方法拿取数据

getUser(){
            Axios.get(`https://cnodejs.org/api/v1/user/${this.$route.params.name}`)
            .then(response=>{
                window.console.log(response)
            })
        }

注意:变量参数用的是`反单引号包裹

猜你喜欢

转载自www.cnblogs.com/raonet/p/11590268.html