Setting props as part of href attribute in VueJS
P粉653045807
P粉653045807 2024-03-31 18:49:48
0
1
361

I have defined an icon component and want to append props to the href link address as part of the URL. How can this be done correctly?

In fact, I want the number of attributes href to look like this:

href="./img/icon.svg#ico_copy"

Vue.component('icon', {
  template: `
  <svg class="iconz">
  <use v-bind:href="'./img/icon.svg#'+ props.label"></use>
  </svg>`,
  props: {
    label: String,
  },
});
  <icon label="ico_copy"></icon>

P粉653045807
P粉653045807

reply all(1)
P粉724737511

You can create a computed property like this:

computed: {
  url() {
    return `./img/icon.svg#${this.label}`;
  }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!