Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
¿Usar Renderless Component es una buena forma de funcionalidad común?

Tengo dos componentes Vue con el mismo método (copiar y pegar). Me gustaría evitar esa duplicación y estoy buscando la mejor manera de hacerlo. Tenga en cuenta que el método usa estado mapeado y acciones de Vuex.

Terminé creando un componente Renderless con el siguiente esquema:

 <script> import { mapState, mapActions } from 'vuex'; export default { name: "CommonHandler", render: () => null, props: { prop: { type: User, required: true, }, }, methods: { ...mapActions({ mapAction1: "mappings/mapAction", }), commonMethod() { /*Use computed variables and actions...*/ }, }, computed: { ...mapState({ users: state => state.users, }), currentUser() { return this.users.find( element => element.id === this.prop.id ); }, }, }; </script>

Luego, en esos dos componentes, creo una instancia del componente anterior, le agrego una ref y simplemente llamo al método común de esta manera:

this.$refs.commonComponent.commonMethod();

¿Es esta una buena manera de resolver este problema?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!