【问题标题】:Building axios url to get from router params with Vue使用 Vue 构建 axios url 以从路由器参数中获取
【发布时间】:2020-09-09 11:42:48
【问题描述】:

我正在尝试构建一个字符串以与 axios 一起使用以从 api 获取某些数据。我似乎无法弄清楚在这种情况下使用计算的或安装的。我当前的代码一直告诉我我的 returnurl 没有定义。任何帮助都会很棒。我什至不知道是否尝试正确构建 URL。

谢谢

<script>
import axios from "axios";

export default {
  name: "GroupList",
  data() {
    return {
      search: "",
      groupName: this.$route.params.group,
      swipedata: []
    };
  },
  mounted() {
    axios.get(returnurl).then(response => (this.swipedata = response.data));
  },
  computed: {
    returnurl() {
      return (
        this.returnurl = "http://localhost:5000/" + this.$route.params.group
      );
    }
  },
  components: {}
};
</script>

我的路由器部分:

{
  path: "/groups/:group",
  component: GroupList,
},

【问题讨论】:

    标签: javascript vue.js vuejs2 vue-router


    【解决方案1】:

    改变这一行

    axios.get(returnurl).then(response => (this.swipedata = response.data));
    

    到

    axios.get(this.returnurl).then(response => (this.swipedata = response.data));
    

    你只是忘记了this :)

    【讨论】:

      猜你喜欢
      • 2019-08-11
      • 1970-01-01
      • 2019-08-15
      • 2015-11-03
      • 2019-10-12
      • 2020-07-28
      • 2021-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多