【问题标题】:how to put return value into URL in java script如何在javascript中将返回值放入URL
【发布时间】:2020-07-24 20:35:21
【问题描述】:

我已经有来自父页面的“breedKey”和返回的“thedate”的值,我怎样才能将这两个值放入 axios.get URL,我想以这种方式在 URL 中替换它们

"https://www.mustavi.com/TimeSeries/?param1={{breedkey}}&param2={{thedate}}"

   props: ["breedKey", "time"],

    data() {
            return {
              thedate: this.time
            };
          },

    async created() {


            try {
              this.promise = axios.get(
                "https://www.mustavi.com/TimeSeries/?param1=nctzenselcaday&param2=2020-04-09"
              );
              const res = await this.promise;

【问题讨论】:

  • 你想这样做,对吧?网址+"/?param1="+myparam1+"&param2="+myparam2?还是我没有正确理解你?

标签: javascript vue.js url url-rewriting vue-component


【解决方案1】:

您可以为此使用template strings

this.promise = axios.get(
 `https://www.mustavi.com/TimeSeries/?param1=${this.breedKey}&param2=${this.thedata}`
);

【讨论】:

  • 我刚刚发现如果我声明 let myparam1 =breedKey; 会出错让 myparam2 = thedate;在尝试之前{}
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-31
  • 1970-01-01
  • 2019-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多