【问题标题】:How to construct a route model binding url with axios?如何用axios构造路由模型绑定url?
【发布时间】:2019-10-10 23:55:12
【问题描述】:

我想写一个带有slug和id的vue Axios URL,但是我做不到。

请帮帮我。

axios.get('http://localhost/BUproject/postsByUser/' + slug / +id)
    .then(response => {
        this.postsByUser = response.data;
        Vue.filter('myOwnTime', function (value) {
            return moment(value).fromNow();
        });
    });

【问题讨论】:

    标签: laravel vue.js


    【解决方案1】:

    从您的代码看来,引号和+ 的位置并没有完全正确地相加。

    你可以很好地进行老式的字符串连接:

    'http://localhost/BUproject/postsByUser/' + slug + '/' +id'
    

    或者如果使用ES6,你可以这样做

    `http://localhost/BUproject/postsByUser/${slug}/${id}`
    

    此外,如果调用将始终与您正在使用的服务器相同,您可以放弃 http://localhost 部分以使其相对于根目录。

    `/BUproject/postsByUser/${slug}/${id}`
    

    All you ever wanted to know about String in javascript

    【讨论】:

      猜你喜欢
      • 2019-09-05
      • 2019-01-10
      • 2016-06-04
      • 1970-01-01
      • 2015-08-28
      • 2019-06-06
      • 2018-02-28
      • 1970-01-01
      • 2021-05-24
      相关资源
      最近更新 更多