[Vuejs]-How to create dynamic HTTP request path

1๐Ÿ‘

โœ…

You need to use the ` symbol to use template strings

execute() {
      this.$gapi
        .request({
          path:
            "https://www.googleapis.com/drive/v3/files/1xTvsBoqCiKE5XfSRklRPBWMbkCtdJSnzGEdT7B76TZM/copy",
          method: "POST"
        })
        .then(response => {
          console.log(response);
          let documentId = response.result.id;

          let imieUcznia = "Alice";
          let requests = [
            {
              replaceAllText: {
                containsText: {
                  text: "{{imieUcznia}}",
                  matchCase: true
                },
                replaceText: imieUcznia
              }
            }
          ];
          this.$gapi
            .request({
              path:
                `https://docs.googleapis.com/v1/documents/${documentId}:batchUpdate`, // <-- here
              method: "POST",
              body: {
                requests
              }
            })
            .then(response => {
              console.log(response);
            });
        });
    },
๐Ÿ‘คMorphyish

2๐Ÿ‘

You can use Javascript Template Literals ie use ` instead of โ€œ

path: `https://docs.googleapis.com/v1/documents/${documentId}:batchUpdate`,
//    ^ Observe here
๐Ÿ‘คvatz88

Leave a comment