Skip to content
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

Vue3 support #60

Open
petr-hybler opened this issue Oct 5, 2020 · 7 comments
Open

Vue3 support #60

petr-hybler opened this issue Oct 5, 2020 · 7 comments

Comments

@petr-hybler
Copy link

Hello, do you plan to implement support for vue3 officially? Or should I rather stick with this unofficial release?

https://github.com/zhuowenli/vue-feather-icons

Because right now, I am facing an issue with using vue3 that it says "Cannot read property 'size' of undefined" in my simple component ...

@mariana-morais
Copy link

Hello, do you plan to implement support for vue3 officially? Or should I rather stick with this unofficial release?

https://github.com/zhuowenli/vue-feather-icons

Because right now, I am facing an issue with using vue3 that it says "Cannot read property 'size' of undefined" in my simple component ...

I'm having this same issue.

@petr-hybler
Copy link
Author

I'm having this same issue.

I sticked with vue2 for now :( for I like it better than vue3 + all those non-compatible packages ...

@zolzaya
Copy link

zolzaya commented Dec 25, 2020

Guys any news?

@ghostvar
Copy link

ghostvar commented Jan 9, 2021

so, because it was too long waiting for compatibility suppport,
i have a some "little hurt tricky" way

lets take a look,
save this as lib, what ever you called it, ex: feathercompt.js
this lib is a tricky way to change render props function rules from vue v2 to v3

import * as VueBase from 'vue';

const comptbl = (ren) => {
  const { attrs, class: cls } = ren.props;
  if(attrs) {
    ren.props = attrs;
    ren.props.class = cls;
  }
  if(Array.isArray(ren.children)) {
    ren.children = ren.children.map((rem) => {
      return comptbl(rem);
    });
  }
  return ren;
}

export default function(Icon, size = "16") {
  const ren = Icon.render(VueBase.h, {props: {size}, data: {}});
  Icon.render = function () {
    return comptbl(ren);
  }
}

and import before you use a component, like this

import { Options, Vue } from 'vue-class-component';
import { BarChart2Icon, InfoIcon } from 'vue-feather-icons';
import featCompt from './lib/feathercompt';

featCompt(BarChart2Icon);
featCompt(InfoIcon);

@Options({
  components: {
    BarChart2Icon,
    InfoIcon
  },
})
export default class Home extends Vue {}

use tag like normal component

<ul>
    <li><router-link to="/"><bar-chart2-icon/>Home</router-link></li>
    <li><router-link to="/about"><info-icon/>About</router-link></li>
</ul>

as result:
image

happy code!

@omarkdev
Copy link

omarkdev commented Aug 27, 2021

@ghostvar You can make a little change to accept the size with a prop in component without the need to define when call the featCompt:

import * as VueBase from 'vue';

const renderIcon = (ren) => {
  const { attrs, class: cls } = ren.props;
  if (attrs) {
    ren.props = attrs;
    ren.props.class = cls;
  }
  if (Array.isArray(ren.children)) {
    ren.children = ren.children.map((rem) => renderIcon(rem));
  }
  return ren;
};

export const makeCompatible = (Icon: any) => {
  const oldRender = Icon.render;

  Icon.render = (props) => renderIcon(oldRender(VueBase.h, { props, data: {} }));
};

@JacoBriers
Copy link

JacoBriers commented Apr 25, 2022

Any news on standard Vue 3 support? I tried the above with Vue 3.2.0, but it does not seem to work.

@lukeJEdwards
Copy link

for vue3 support https://www.npmjs.com/package/vue-feather-icons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants