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

347
Views
¿Cómo usar dos componentes esbeltos en diferentes páginas con identificaciones distintas?

Me gustaría usar dos componentes esbeltos no relacionados en dos páginas distintas de un sitio web, digamos /cats y /dogs así que en main.js tengo

 import App from './App.svelte'; //this is empty import ListCats from './ListCats.svelte'; import ListDogs from './ListDogs.svelte'; new ListCats({ target: document.querySelector('#list-cats'), }); new ListDogs({ target: document.querySelector('#list-dogs'), }); const app = new App({ target: document.body }); export default app;

El problema es ese error:

 Uncaught Error: 'target' is a required option at new SvelteComponentDev (index.mjs:1993:19) at new ListDogs (ListDogs.svelte:76:39) at main.js:9:1 at main.js:24:2

Esto surge porque la página /cats no tiene #list-dogs y /dogs no tiene #list-cats y ambas páginas importan el mismo bundle.js de svelte.

¿Cómo puedo evitar este problema?

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

0

probar

 let target = document.querySelector('#list-cats'); if (target) new ListCats({ target }); target = document.querySelector('#list-dogs'); if (target) new ListDogs({ target });
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!