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

524
Views
¿Cómo puedo agregar HTML interno (o texto interno) usando la función h ()?

Por alguna razón, necesito usar DOM virtual y aquí está mi código,

 // test.js import { h, ref } from 'vue' const ButtonCounter = { name: 'button-counter', props: { tag: { type: String, default: 'div' } }, setup (props) { const sliderClass = ref('slider-slide') return () => { return h(props.tag, { class: sliderClass.value }) } } } export { ButtonCounter }
 <template> <div> <div id="components-demo"> <!-- putting <img>tag in virtual DOM --> <button-counter tag="span"><img src="../assets/images/red.jpg" alt=""></button-counter> </div> </div> </template> <script> import { ButtonCounter } from '../assets/js/test' import { Swiper, SwiperSlide } from 'swiper/vue' import 'swiper/css' export default { name: 'TestView', components: { ButtonCounter, Swiper, SwiperSlide }, setup () { } } </script>

Esperaba que se agregara <img src="../assets/images/red.jpg" alt=""> en <span class="slider-slide"></span> pero el resultado fue https:// i.stack.imgur.com/DR4Te.png no se agregó.

¿Cómo puedo hacer que funcione? Gracias por tu ayuda.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La función de representación h no representa automáticamente el alcance (es decir, la parte interna/envuelta del componente) sin que usted se lo indique explícitamente.

Este fragmento debería hacerlo:

 setup (props, { slots }) { const sliderClass = ref('slider-slide'); return () => { return h(props.tag, { class: sliderClass.value }, slots.default()); }; }

Tenga en cuenta la adición de la llamada a slots.default() , agregada como parámetro children para la función de representación.

about 4 years ago · Juan Pablo Isaza Report
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!