FortAwesome / vue-fontawesome

Font Awesome Vue component
https://fontawesome.com
MIT License
2.38k stars 132 forks source link

Icons not working in Vue3 while rendering with v-html #412

Open mshishkov opened 1 year ago

mshishkov commented 1 year ago
################################ index.hml #######################################
<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
    </head>
    <body>
        <div id="app">
            Element not rendered: <span v-html="faElem"></span>
            <br>
            While simple usage is working: <fa icon="fa-solid fa-envelope" />
        </div>
        <script src="js/app.js"></script>
    </body>
</html>
################################ app.js #######################################
import './bootstrap';
import { createApp } from 'vue';

// FontAwesome
import { library } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { faEnvelope } from '@fortawesome/free-solid-svg-icons';
library.add(faEnvelope);

createApp({
    data() {
        return {
             faElem: `<fa icon="fa-solid fa-envelope" />`
        }
    }
})
    .component('fa', FontAwesomeIcon)
    .mount('#app');

That's what rendered image

CodelineRed commented 1 year ago

This behaviour is intended by Vue and is not related to FA. A google search like "v-html with components" could help you to try a different approach. How to use components in v-html