[Vuejs]-SetAttribute is not a function when referencing from a variable

2👍

The value of this.icon in that function is the string to which it was initialized in the .data() method. It’s not an actual <svg> element.

Also, using .setAttribute() as the value of a return statement doesn’t make a lot of sense anyway, as it always returns undefined.

👤Pointy

3👍

Since the value of this.icon is a string you could change the string dynmically before you return it. Your computed method could look like this:

computed: {
    appendDimension() {   
      return this.icon.replace("<svg ", "<svg width='" + this.dimension + "' ");
    }
  }

You should also change your <code v-text="appendDimension"></code> to <code v-html="appendDimension"></code> since you want to render the html and not the string itself. But that’s my guess 😉

Leave a comment