Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue.js - Rendering Font Awesome using unicode syntax inside component not working

I have the following Font Awesome icon defined in my component template using its Unicode syntax. However, it doesn't seem to render inside the view. The output I get is \uf040.

<template>
  ...
    <span class="text-muted icon-before" data-icon="\uf040" >
      Edit
    </span>
  ...
</template>

CSS:

.icon-before[data-icon]:before {
  color: inherit;
  content: attr(data-icon);
  font-family: 'FontAwesome';
  font-style: normal;
}

Note: I'm using the component inside an asp.net MVC razor view.

Any ideas how I can fix this?

like image 780
adam78 Avatar asked Nov 17 '25 12:11

adam78


1 Answers

You need to unescape the string '\uf040'. You can do that with a filter, like so:

new Vue({
  el: '#app',
  filters: {
    unescape: v => unescape(v)
  }
})
.icon-before[data-icon]:before {
  color: inherit;
  content: attr(data-icon);
  font-family: 'FontAwesome';
  font-style: normal;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.10/vue.min.js"></script>

<div id="app">
  <span class="text-muted icon-before" :data-icon="'\uf040' | unescape" >
    Edit
  </span>
</div>
like image 91
thanksd Avatar answered Nov 20 '25 01:11

thanksd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!