-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vue 3 support #230
Comments
I was wanting to use some font awesome icons in a project using vite, which uses vue 3. Since this doesn't yet support vue 3, I have been unable to do so (so far). Vue 3 support would be greatly appreciated, and will be necessary when vue 3 is fully released. |
Vue 3 is now at release candidate stage, it would be good to have an update on this issue! From a quick look at the source it seems there is no quick workaround. |
I am getting this error:
Not sure if it is related to Vue 3? I think it is, because it used to work with Vue 2. I am using |
vue-fontawesome doesn’t currently support Vue 3, hence this ticket. |
Very frustrating. I am not even sure whether I should downgrade Vue or wait for a fix for @robmadole is there any ETA? |
@pedzed I've just been manually downloading the svgs and including them by hand, but that's not an acceptable fix now that vue 3 is in it's RC stage. Hopefully we get something soon. |
No answer, no ETA... |
Hi all! I've just created a component for Font Awesome which works with Vue 3. All you need to do is add this file as Also, it's fully reactive, using Vue 3's new Composition API. You still need to add your icons to the library <template>
<svg xmlns="http://www.w3.org/2000/svg" :class="$props.class" :viewBox="`0 0 ${width} ${height}`">
<path fill="currentColor" :d="svgPath"/>
</svg>
</template>
<script>
import { defineComponent, computed } from 'vue'
import { findIconDefinition } from '@fortawesome/fontawesome-svg-core'
export default defineComponent({
name: 'FontAwesomeIcon',
props: {
icon: {
type: String,
required: true
},
class: String
},
setup (props) {
const definition = computed(() => findIconDefinition({
prefix: 'fas',
iconName: props.icon
}))
const width = computed(() => definition.value.icon[0])
const height = computed(() => definition.value.icon[1])
const svgPath = computed(() => definition.value.icon[4])
return { width, height, svgPath }
}
})
</script> |
Just to clarify how I'm using this thing (where
// @/plugins/font-awesome.ts
import { library } from '@fortawesome/fontawesome-svg-core'
import { fas } from '@fortawesome/free-solid-svg-icons'
import FontAwesomeIcon from '@/lib/FontAwesomeIcon.vue'
library.add(fas)
export {
FontAwesomeIcon
} // My @/main.ts
import { createApp } from 'vue'
import App from '@/App.vue'
import router from '@/router'
import { FontAwesomeIcon } from '@/plugins/font-awesome'
createApp(App)
.use(router)
.component('fa', FontAwesomeIcon)
.mount('#app') In my case, as I've registered the component globally as |
I've just release All: please give this pre-release a try and let me know what you think. |
The npm ERR! code ETARGET
npm ERR! notarget No matching version found for @fortawesome/vue-fontawesome@3.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/raj/.npm/_logs/2020-09-04T02_35_55_060Z-debug.log However, your instruction here to use the full version name does work: Thought you may want to update the |
@james2mid Awesome ;-) Works great for displaying static icons (no support for sizing, transformations, ...). Thank you very much ! |
yeah @rajsinghUSA right, I got the same error and I fixed with this : 1-) Firstly run these npm commands in your project's main folder;
2-) Then create 'FontAwesomeIcon.vue' file with this content below under /libs path (you can create a folder in the main path)
3-) Create 'font-awesome.ts' file with this content below under /plugins path (you can create a folder in the main path)
4-) Finally register FontAwesome as a global component in main.ts file;
You can use like this: Brand Logo Icon Example:
Regular Icon Example:
I hope it helps everyone, especially for beginners like me :) |
The posted solution doesn't seem to work for duotone icons: |
The current package breaks Vue HMR |
Fixed thanks to @halilyuce with the first command, the repository indicate to enter this command to load Vue-3 fontawesome |
We are able to use fontawesome icons in vue3 using a custom component published as an early-release at FortAwesome/vue-fontawesome#230
@halilyuce solution didn't work for me. I'm getting a TypeError: cannot read propery 'icon' of undefined at the FontAwesomeIcon.vue component.
finIconDefinition is returning undefined, and when I looked at the definition in the @fortawesome/fontawesome-svg-core/index.d.ts it isn't defined, only it's type. |
My mistake was having the 'fa', FontAwesomeIcon in the use() instead of in the .component(). |
I followed all the steps but I'm getting an error message : Thanks for the help! |
@jvcmarcenes In case you haven't solved your problem yet: I had the same issue. font-awesome.ts imports FontAwesomeIcon.vue from "@/libs/FontAwesomeIcon.vue" and main.ts imports FontAwesomeIcon from "@/plugins/font-awesome" - but my project didn't have @libs or @plugins setup. Once I changed the imports to their relative file paths, it all worked smoothly. @JStephens83 you may be having a variant of the same issue, |
@JoshuaHull My imports were correct. My error was that in the FontAwesomeIcon.vue, the default for the 'type' props was set to 'fab', and I hand't installed the solid icons, only the regulars, so I changed the default to 'far' and now it works |
@JoshuaHull Unfortunately the issue does not come from here but really from the "@" which is not recognized, Still looking for what I did wrong. |
@JoshuaHull when you say "my project didn't have @libs or @plugins setup." what do you mean exactly ? |
I've done so many tinkering (adding a tsconfig.json and a vue.config.js files and many other things) that I don't really know what fixed it but in the end it's now working. |
And you made the libs folder with the FontAwesomeIcone.vue code? |
Yes I manually created the folder and added FontAwesomeIcon.vue in it |
@JStephens83 This is what I have and it's working for me. I changed my folder name from libs to lib but that shouldn't matter. I had to restart my server once they were created. font-awesome.ts
FontAwesome.vue
project structure :
|
in the newest prerelease install there seems to be a vue component included already, works great |
@kamaslau Yes I have the exact same organization and content. |
|
@MrBrax |
How can i set icon's prefix on this vue component? |
@MrBrax and the library import { library } from "@fortawesome/fontawesome-svg-core"; and explicit styles https://github.com/FortAwesome/vue-fontawesome#using-solid-icons |
<script> import { defineComponent, computed } from "vue"; import { findIconDefinition } from "@fortawesome/fontawesome-svg-core"; export default defineComponent({ name: "FontAwesomeIcon", props: { icon: { type: String, required: true }, type: { type: String, default: "fas", required: false }, class: String }, setup(props) { const definition = computed(() => findIconDefinition({ prefix: props.type, iconName: props.icon }) ); const width = computed(() => definition.value.icon[0]); const height = computed(() => definition.value.icon[1]); const svgPath = computed(() => definition.value.icon[4]); return { width, height, svgPath }; } }); </script> Awesome!! Thank you. |
Anybody know how to get this working with the pro version? |
Yes. Doesn't work for me. |
I had the same issue with: package.json "@fortawesome/fontawesome-svg-core": "^1.2.36",
"@fortawesome/free-brands-svg-icons": "^5.15.4",
"@fortawesome/free-solid-svg-icons": "^5.15.4",
"@fortawesome/vue-fontawesome": "^2.0.2", Relying on a previous project where it worked, I upgraded |
Hi, Did someone make it works with the version 6 in beta? package.json
I have an error with npm i --save @fortawesome/vue-fontawesome@latest like mentioned in the v6 docs or npm i --save @fortawesome/vue-fontawesome@prerelease indicated here in github
|
Hey there everyone. I am going through and cleaning up our Vue issues and found this. We officially support Vue 2 and Vue 3 now. If you need more info on how to install or use you can checkout out our docs here. |
Is your feature request related to a problem? Please describe.
Vue 3 is already in late beta and some of the deeper APIs are incompatible with Vue 2. It would be nice to have a Vue 3 compatible fontawesome component.
Describe the solution you'd like
Upgrade the component to use the new render APIs: vuejs/rfcs#28
The text was updated successfully, but these errors were encountered: