Rohit Kumar
Rohit Kumar

Reputation: 719

syntax error on concatenating variables to the string

Here i'm doing the concatination while setting the state.but it's giving the syntax error.i'm obviously a newbie in vue js world.

export default{
  data: function(){
    return{
      http_options:{
              headers:{
                '"Authorization": "Basic '+ this.$store.state.authorization + '"'
              }
             }, 

Module build failed: SyntaxError: Unexpected token (11:42)

 http_options:{
                headers:{
                '"Authorization": "Basic '+ this.$store.state.authorization + '"'
                                          ^
                }
              }

Upvotes: 0

Views: 50

Answers (2)

victorhazbun
victorhazbun

Reputation: 841

Use ES6 Template Strings

headers:{
  "Authorization": `Basic ${this.$store.state.authorization}`                     
}

Upvotes: 0

logee
logee

Reputation: 5067

You have a mismatch of ' and ". Just use:

 headers:{
    Authorization: "Basic "+ this.$store.state.authorization
 }

of if you need the ' around the this.$store.state.authorization (which I HIGHLY doubt if you're doing basic auth) then

 headers:{
    Authorization: "Basic '"+ this.$store.state.authorization + "'"
 }

Upvotes: 1

Related Questions