将道具值传递给axios中的url不起作用

Posted

技术标签:

【中文标题】将道具值传递给axios中的url不起作用【英文标题】:passing the props value to the url in axios is not working 【发布时间】:2019-09-21 12:53:24 【问题描述】:

我正在尝试将变量发送到 axios 的 url,但这样做会为我提供错误 404,甚至 '' 大括号在错误时更改为 '%'

从'axios'导入axios 导出默认

mounted()
    this.$parent.$on('create_new_lesson',(seriesId)=>
       this.seriesId = seriesId

        $('#createLesson').modal()
    )
,
data()

    return
        title:'',
        description:'',
        episode_number:'',
        video_id:'',
        seriesId:''
    
,

methods:
   createLesson()
   
    Axios.post('/admin/$this.seriesId/lessons',
        title:this.title,
        description:this.description,
        episode_number:this.episode_number,
        video_id:this.video_id
     ).then(resp =>
       console.log(resp)
     ). catch(resp =>
       console.log(resp)
     )
   

它应该返回将创建的数据发送到控制台enter image description here

【问题讨论】:

试试传统的串联'/admin/'+this.seriesId+'/lessons' 感谢您的回复,以下内容对我有用 【参考方案1】:

对于字符串插值,您需要使用反引号 ` 而不是单引号 '

`/admin/$this.seriesId/lessons`

【讨论】:

以上是关于将道具值传递给axios中的url不起作用的主要内容,如果未能解决你的问题,请参考以下文章