【问题标题】:passing the props value to the url in axios is not working将道具值传递给axios中的url不起作用
【发布时间】: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'
  • 感谢您的回复,以下内容对我有用

标签: ajax laravel vue.js


【解决方案1】:

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

`/admin/${this.seriesId}/lessons`

【讨论】:

    猜你喜欢
    • 2018-05-31
    • 1970-01-01
    • 2015-09-16
    • 2021-07-30
    • 2017-11-19
    • 2018-08-02
    • 2019-06-30
    • 2018-03-26
    • 2021-09-27
    相关资源
    最近更新 更多